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



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

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

Class Method Details

.allObject



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

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



38
39
40
# File 'lib/iso/subtag.rb', line 38

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

.defaultObject



34
35
36
# File 'lib/iso/subtag.rb', line 34

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

.find(code) ⇒ Object



30
31
32
# File 'lib/iso/subtag.rb', line 30

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

Instance Method Details

#==(object) ⇒ Object



10
11
12
# File 'lib/iso/subtag.rb', line 10

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

#full_nameObject



18
19
20
# File 'lib/iso/subtag.rb', line 18

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

#nameObject



14
15
16
# File 'lib/iso/subtag.rb', line 14

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