Class: DataRequestTable
- Inherits:
-
Object
- Object
- DataRequestTable
- Defined in:
- lib/data_request.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #approx_interval ⇒ Object
- #frequencies ⇒ Object
-
#initialize(path) ⇒ DataRequestTable
constructor
A new instance of DataRequestTable.
- #table_id ⇒ Object
- #variable_entries ⇒ Object
- #variable_ids ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path) ⇒ DataRequestTable
Returns a new instance of DataRequestTable.
241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/data_request.rb', line 241 def initialize(path) @path = path begin @data = JSON.parse File.read(path) rescue JSON::ParserError => e raise "file #{path}: #{e.}" end raise "missing 'Header' entry at #{@path}" unless @data.has_key?("Header") raise "missing 'table_id' in 'Header' entry at #{@path}" unless @data["Header"].has_key?("table_id") raise "missing 'mip_era' in 'Header' entry at #{@path}" unless @data["Header"].has_key?("mip_era") end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
239 240 241 |
# File 'lib/data_request.rb', line 239 def path @path end |
Instance Method Details
#approx_interval ⇒ Object
276 277 278 |
# File 'lib/data_request.rb', line 276 def approx_interval @data["Header"]["approx_interval"] end |
#frequencies ⇒ Object
254 255 256 |
# File 'lib/data_request.rb', line 254 def frequencies (@data["variable_entry"].values.map {|v| v["frequency"]}).uniq end |
#table_id ⇒ Object
281 282 283 284 285 |
# File 'lib/data_request.rb', line 281 def table_id # chop of the "Table " prefix as it is not allowed according to the "controlled vocabularies" raise "can not determine table_id: <#{@path}>" unless /Table (?<table_id>\w+)$/ =~ @data["Header"]["table_id"] table_id end |
#variable_entries ⇒ Object
264 265 266 267 268 |
# File 'lib/data_request.rb', line 264 def variable_entries @data["variable_entry"].keys.sort.map do |k| TableVarEntry.new(variable_entry_key: k, entry_data: @data["variable_entry"][k], table: self) end end |
#variable_ids ⇒ Object
259 260 261 |
# File 'lib/data_request.rb', line 259 def variable_ids @data["variable_entry"].keys.sort end |
#version ⇒ Object
271 272 273 |
# File 'lib/data_request.rb', line 271 def version @data["Header"]["data_specs_version"] end |