Class: ControlledVocabularies
- Inherits:
-
Hash
- Object
- Hash
- ControlledVocabularies
- Defined in:
- lib/controlled_vocabularies.rb
Overview
Class Method Summary collapse
- .hash_from_json_file(path) ⇒ Object
- .new_from_dir(cmip6_cvs_dir) ⇒ Object
- .print_experiment_ids(cv_file) ⇒ Object
Instance Method Summary collapse
-
#initialize(json_files) ⇒ ControlledVocabularies
constructor
A new instance of ControlledVocabularies.
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.}" 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 |
.print_experiment_ids(cv_file) ⇒ Object
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 |