Class: StrainCode::Catalogue

Inherits:
Object
  • Object
show all
Defined in:
lib/strain-code/catalogue.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#codesObject

Returns the value of attribute codes.



28
29
30
# File 'lib/strain-code/catalogue.rb', line 28

def codes
  @codes
end

#country_codeObject

Returns the value of attribute country_code.



28
29
30
# File 'lib/strain-code/catalogue.rb', line 28

def country_code
  @country_code
end

#nameObject

Returns the value of attribute name.



28
29
30
# File 'lib/strain-code/catalogue.rb', line 28

def name
  @name
end

#name_enObject

Returns the value of attribute name_en.



28
29
30
# File 'lib/strain-code/catalogue.rb', line 28

def name_en
  @name_en
end

#organizationObject

Returns the value of attribute organization.



28
29
30
# File 'lib/strain-code/catalogue.rb', line 28

def organization
  @organization
end

#urlObject

Returns the value of attribute url.



29
30
31
# File 'lib/strain-code/catalogue.rb', line 29

def url
  @url
end

#url_patternObject

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_pathObject



4
5
6
# File 'lib/strain-code/catalogue.rb', line 4

def catalogues_path
  File.join(StrainCode.data_path, 'catalogues.yaml')
end

.catalogues_sourceObject



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