Class: BCP47::Subtag

Inherits:
Object
  • Object
show all
Defined in:
lib/bcp47/subtag.rb

Direct Known Subclasses

Language, Region

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, options = {}) ⇒ Subtag

Returns a new instance of Subtag.



5
6
7
# File 'lib/bcp47/subtag.rb', line 5

def initialize(code, options={})
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/bcp47/subtag.rb', line 3

def code
  @code
end

Class Method Details

.allObject



21
22
23
24
25
26
27
# File 'lib/bcp47/subtag.rb', line 21

def self.all
  YAML.load_file(self::DEFINITIONS_FILE).map do |code, options|
    symbolized_options = {}
    options.keys.each { |key| symbolized_options[key.to_sym] = options[key] } if options
    new(code, symbolized_options)
  end
end

.codesObject



37
38
39
# File 'lib/bcp47/subtag.rb', line 37

def self.codes
  all.map(&:code)
end

.defaultObject



33
34
35
# File 'lib/bcp47/subtag.rb', line 33

def self.default
  find(self::DEFAULT_CODE)
end

.find(code) ⇒ Object



29
30
31
# File 'lib/bcp47/subtag.rb', line 29

def self.find(code)
  all.find {|subtag| subtag.code == code }
end

Instance Method Details

#==(object) ⇒ Object



9
10
11
# File 'lib/bcp47/subtag.rb', line 9

def ==(object)
  code == object.code
end

#full_nameObject



17
18
19
# File 'lib/bcp47/subtag.rb', line 17

def full_name
  "#{code} - #{name}"
end

#nameObject



13
14
15
# File 'lib/bcp47/subtag.rb', line 13

def name
  I18n.t(code, scope: i18n_scope)
end