Class: Ddr::Language

Inherits:
Struct
  • Object
show all
Defined in:
app/models/ddr/language.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



2
3
4
# File 'app/models/ddr/language.rb', line 2

def code
  @code
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



2
3
4
# File 'app/models/ddr/language.rb', line 2

def label
  @label
end

Class Method Details

.allObject



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

.codesObject



28
29
30
# File 'app/models/ddr/language.rb', line 28

def self.codes
  keystore.keys
end

.configObject



4
5
6
# File 'app/models/ddr/language.rb', line 4

def self.config
  @config ||= YAML.load_file(::File.expand_path('../../../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

.keystoreObject



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_sObject



32
33
34
# File 'app/models/ddr/language.rb', line 32

def to_s
  label
end