Class: ISO::Subtag

Inherits:
Object
  • Object
show all
Defined in:
lib/iso/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.



7
8
9
10
# File 'lib/iso/subtag.rb', line 7

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

Class Method Details

.allObject



24
25
26
27
28
29
30
# File 'lib/iso/subtag.rb', line 24

def self.all
  @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



40
41
42
# File 'lib/iso/subtag.rb', line 40

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

.defaultObject



36
37
38
# File 'lib/iso/subtag.rb', line 36

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

.find(code) ⇒ Object



32
33
34
# File 'lib/iso/subtag.rb', line 32

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

Instance Method Details

#==(object) ⇒ Object



12
13
14
# File 'lib/iso/subtag.rb', line 12

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

#full_nameObject



20
21
22
# File 'lib/iso/subtag.rb', line 20

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

#nameObject



16
17
18
# File 'lib/iso/subtag.rb', line 16

def name
  @options[:name] || I18n.t(code, :scope => i18n_scope)
end