Class: Ddr::Language
- Inherits:
-
Struct
- Object
- Struct
- Ddr::Language
- Defined in:
- app/models/ddr/language.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#label ⇒ Object
Returns the value of attribute label.
Class Method Summary collapse
- .all ⇒ Object
- .call(obj) ⇒ Object
- .codes ⇒ Object
- .config ⇒ Object
- .find_by_code(code) ⇒ Object
- .keystore ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code
2 3 4 |
# File 'app/models/ddr/language.rb', line 2 def code @code end |
#label ⇒ Object
Returns the value of attribute label
2 3 4 |
# File 'app/models/ddr/language.rb', line 2 def label @label end |
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'app/models/ddr/language.rb', line 12 def self.all keystore.values end |
.call(obj) ⇒ Object
16 17 18 |
# File 'app/models/ddr/language.rb', line 16 def self.call(obj) obj.language.map { |lang| find_by_code(lang) } end |
.codes ⇒ Object
28 29 30 |
# File 'app/models/ddr/language.rb', line 28 def self.codes keystore.keys end |
.config ⇒ Object
4 5 6 |
# File 'app/models/ddr/language.rb', line 4 def self.config @config ||= YAML.load_file(::File.('../../../config/aux/language.yml', __dir__)) end |
.find_by_code(code) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/models/ddr/language.rb', line 20 def self.find_by_code(code) return unless code keystore.fetch(code) rescue KeyError => _ raise Ddr::NotFoundError, "Language code '#{code}' not found." end |
.keystore ⇒ Object
8 9 10 |
# File 'app/models/ddr/language.rb', line 8 def self.keystore @keystore ||= Hash[config.map { |entry| [entry['code'], new(entry).freeze] }].freeze end |
Instance Method Details
#to_s ⇒ Object
32 33 34 |
# File 'app/models/ddr/language.rb', line 32 def to_s label end |