1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
require 'yaml'
module ISO
class Subtag
attr_reader :code
def initialize(code, options={})
@code = code
@options = options
end
def ==(object)
code == object.code
end
def name
@options[:name] || I18n.t(code, :scope => i18n_scope)
end
def full_name
"#{code} - #{name}"
end
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
def self.find(code)
all.find {|subtag| subtag.code == code }
end
def self.default
find(self::DEFAULT_CODE)
end
def self.codes
all.map(&:code)
end
private
def i18n_scope
%w(vendor iso).join('.')
end
end
end
|