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(code) ⇒ Catalogue
constructor
A new instance of Catalogue.
Constructor Details
#initialize(code) ⇒ Catalogue
Returns a new instance of Catalogue.
30 31 32 33 |
# File 'lib/strain_code/catalogue.rb', line 30 def initialize(code) code = self.class.catalogue_hash(code) unless code.is_a?(Hash) code.each { |k, v| self.send("#{k}=", v) unless k =~ /^_/ } if code end |
Instance Attribute Details
#codes ⇒ Object
Returns the value of attribute codes.
27 28 29 |
# File 'lib/strain_code/catalogue.rb', line 27 def codes @codes end |
#country_code ⇒ Object
Returns the value of attribute country_code.
27 28 29 |
# File 'lib/strain_code/catalogue.rb', line 27 def country_code @country_code end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/strain_code/catalogue.rb', line 27 def name @name end |
#name_en ⇒ Object
Returns the value of attribute name_en.
27 28 29 |
# File 'lib/strain_code/catalogue.rb', line 27 def name_en @name_en end |
#organization ⇒ Object
Returns the value of attribute organization.
27 28 29 |
# File 'lib/strain_code/catalogue.rb', line 27 def organization @organization end |
#url ⇒ Object
Returns the value of attribute url.
28 29 30 |
# File 'lib/strain_code/catalogue.rb', line 28 def url @url end |
#url_pattern ⇒ Object
Returns the value of attribute url_pattern.
28 29 30 |
# File 'lib/strain_code/catalogue.rb', line 28 def url_pattern @url_pattern end |
Class Method Details
.catalogue(code) ⇒ Object
21 22 23 24 |
# File 'lib/strain_code/catalogue.rb', line 21 def catalogue(code) hsh = catalogue_hash(code) 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) hsh = 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 |