Class: StrainCode::Catalogue
- Inherits:
-
Object
- Object
- StrainCode::Catalogue
- Defined in:
- lib/strain-code/catalogue.rb
Instance Attribute Summary collapse
-
#codes ⇒ Object
Returns the value of attribute codes.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_en ⇒ Object
Returns the value of attribute name_en.
-
#organization ⇒ Object
Returns the value of attribute organization.
-
#url ⇒ Object
Returns the value of attribute url.
-
#url_pattern ⇒ Object
Returns the value of attribute url_pattern.
Class Method Summary collapse
- .catalogue(code) ⇒ Object
- .catalogue_hash(code) ⇒ Object
- .catalogues_path ⇒ Object
- .catalogues_source ⇒ Object
Instance Method Summary collapse
-
#initialize(hash) ⇒ Catalogue
constructor
A new instance of Catalogue.
Constructor Details
#initialize(hash) ⇒ Catalogue
Returns a new instance of Catalogue.
31 32 33 |
# File 'lib/strain-code/catalogue.rb', line 31 def initialize(hash) hash.each { |k, v| self.send("#{k}=", v) unless k =~ /^_/ } end |
Instance Attribute Details
#codes ⇒ Object
Returns the value of attribute codes.
28 29 30 |
# File 'lib/strain-code/catalogue.rb', line 28 def codes @codes end |
#country_code ⇒ Object
Returns the value of attribute country_code.
28 29 30 |
# File 'lib/strain-code/catalogue.rb', line 28 def country_code @country_code end |
#name ⇒ Object
Returns the value of attribute name.
28 29 30 |
# File 'lib/strain-code/catalogue.rb', line 28 def name @name end |
#name_en ⇒ Object
Returns the value of attribute name_en.
28 29 30 |
# File 'lib/strain-code/catalogue.rb', line 28 def name_en @name_en end |
#organization ⇒ Object
Returns the value of attribute organization.
28 29 30 |
# File 'lib/strain-code/catalogue.rb', line 28 def organization @organization end |
#url ⇒ Object
Returns the value of attribute url.
29 30 31 |
# File 'lib/strain-code/catalogue.rb', line 29 def url @url end |
#url_pattern ⇒ Object
Returns the value of attribute url_pattern.
29 30 31 |
# File 'lib/strain-code/catalogue.rb', line 29 def url_pattern @url_pattern end |
Class Method Details
.catalogue(code) ⇒ Object
21 22 23 24 25 |
# File 'lib/strain-code/catalogue.rb', line 21 def catalogue(code) hsh = catalogue_hash(code) @catalogue ||= {} @catalogue[hsh] ||= new(hsh) if hsh end |
.catalogue_hash(code) ⇒ Object
15 16 17 18 19 |
# File 'lib/strain-code/catalogue.rb', line 15 def catalogue_hash(code) catalogues_source['catalogues'].find do |i| i['codes'].include? code.to_s.upcase end end |
.catalogues_path ⇒ Object
4 5 6 |
# File 'lib/strain-code/catalogue.rb', line 4 def catalogues_path File.join(StrainCode.data_path, 'catalogues.yaml') end |
.catalogues_source ⇒ Object
8 9 10 11 12 13 |
# File 'lib/strain-code/catalogue.rb', line 8 def catalogues_source @catalogues_source ||= YAML.load_file( catalogues_path, permitted_classes: [OpenStruct, Symbol, Date] ) end |