class BCP47::Subtag

Attributes

code[R]

Public Class Methods

all() click to toggle source
# 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
codes() click to toggle source
# File lib/bcp47/subtag.rb, line 37
def self.codes
  all.map(&:code)
end
default() click to toggle source
# File lib/bcp47/subtag.rb, line 33
def self.default
  find(self::DEFAULT_CODE)
end
find(code) click to toggle source
# File lib/bcp47/subtag.rb, line 29
def self.find(code)
  all.find {|subtag| subtag.code == code }
end
new(code, options={}) click to toggle source
# File lib/bcp47/subtag.rb, line 5
def initialize(code, options={})
  @code = code
end

Public Instance Methods

==(object) click to toggle source
# File lib/bcp47/subtag.rb, line 9
def ==(object)
  code == object.code
end
full_name() click to toggle source
# File lib/bcp47/subtag.rb, line 17
def full_name
  "#{code} - #{name}"
end
name() click to toggle source
# File lib/bcp47/subtag.rb, line 13
def name
  I18n.t(code, scope: i18n_scope)
end

Private Instance Methods

i18n_scope() click to toggle source
# File lib/bcp47/subtag.rb, line 42
def i18n_scope
  %w(vendor bcp47).join('.')
end