Class: ISO::Subtag
- Inherits:
-
Object
- Object
- ISO::Subtag
- Defined in:
- lib/iso/subtag.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Class Method Summary collapse
Instance Method Summary collapse
- #==(object) ⇒ Object
- #full_name ⇒ Object
-
#initialize(code, options = {}) ⇒ Subtag
constructor
A new instance of Subtag.
- #name ⇒ Object
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, ={}) @code = code @options = end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/iso/subtag.rb', line 5 def code @code end |
Class Method Details
.all ⇒ Object
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, | = {} .keys.each { |key| [key.to_sym] = [key] } if new(code, ) end end |
.codes ⇒ Object
40 41 42 |
# File 'lib/iso/subtag.rb', line 40 def self.codes all.map(&:code) end |
.default ⇒ Object
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_name ⇒ Object
20 21 22 |
# File 'lib/iso/subtag.rb', line 20 def full_name "#{code} - #{name}" end |
#name ⇒ Object
16 17 18 |
# File 'lib/iso/subtag.rb', line 16 def name @options[:name] || I18n.t(code, :scope => i18n_scope) end |