Class: ControlledVocabularies

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

Overview

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_files) ⇒ ControlledVocabularies

Returns a new instance of ControlledVocabularies.



20
21
22
23
24
25
# File 'lib/controlled_vocabularies.rb', line 20

def initialize(json_files)  
  json_files.each do |f|
    h = ControlledVocabularies.hash_from_json_file f
    merge! h
  end    
end

Class Method Details

.hash_from_json_file(path) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/controlled_vocabularies.rb', line 28

def self.hash_from_json_file(path)
  begin
    JSON.parse(File.read(path), object_class: Hash)
  rescue JSON::ParserError => e
    raise "file #{path}: #{e.message}"
  end
end

.new_from_dir(cmip6_cvs_dir) ⇒ Object



15
16
17
# File 'lib/controlled_vocabularies.rb', line 15

def self.new_from_dir(cmip6_cvs_dir)
  ControlledVocabularies.new Dir["#{cmip6_cvs_dir}/*.json"]
end


7
8
9
10
11
12
# File 'lib/controlled_vocabularies.rb', line 7

def self.print_experiment_ids(cv_file)
  cv = ControlledVocabularies.new [cv_file]
  cv['experiment_id'].each do |k,v|
    puts "#{k} #{v['start_year']}-#{v['end_year']} parent:#{v['parent_experiment_id'].join(', ')}"
  end
end