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
5 6 7 8 |
# File 'lib/iso/subtag.rb', line 5 def initialize(code, ={}) @code = code @options = end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/iso/subtag.rb', line 3 def code @code end |
Class Method Details
.all ⇒ Object
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, | = {} .keys.each { |key| [key.to_sym] = [key] } if new(code, ) end end |
.codes ⇒ Object
38 39 40 |
# File 'lib/iso/subtag.rb', line 38 def self.codes all.map(&:code) end |
.default ⇒ Object
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_name ⇒ Object
18 19 20 |
# File 'lib/iso/subtag.rb', line 18 def full_name "#{code} - #{name}" end |
#name ⇒ Object
14 15 16 |
# File 'lib/iso/subtag.rb', line 14 def name @options[:name] || I18n.t(code, :scope => i18n_scope) end |