Class: DataRequestTable

Inherits:
Object
  • Object
show all
Defined in:
lib/data_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message}"
  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

#pathObject (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_intervalObject



276
277
278
# File 'lib/data_request.rb', line 276

def approx_interval
  @data["Header"]["approx_interval"]
end

#frequenciesObject



254
255
256
# File 'lib/data_request.rb', line 254

def frequencies
  (@data["variable_entry"].values.map {|v| v["frequency"]}).uniq
end

#table_idObject



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_entriesObject



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_idsObject



259
260
261
# File 'lib/data_request.rb', line 259

def variable_ids
  @data["variable_entry"].keys.sort
end

#versionObject



271
272
273
# File 'lib/data_request.rb', line 271

def version
  @data["Header"]["data_specs_version"]
end