Class: BCP47::Subtag
- Inherits:
-
Object
- Object
- BCP47::Subtag
- Defined in:
- lib/bcp47/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.
5 6 7 |
# File 'lib/bcp47/subtag.rb', line 5 def initialize(code, ={}) @code = code end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/bcp47/subtag.rb', line 3 def code @code end |
Class Method Details
.all ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bcp47/subtag.rb', line 21 def self.all YAML.load_file(self::DEFINITIONS_FILE).map do |code, | = {} .keys.each { |key| [key.to_sym] = [key] } if new(code, ) end end |
.codes ⇒ Object
37 38 39 |
# File 'lib/bcp47/subtag.rb', line 37 def self.codes all.map(&:code) end |
.default ⇒ Object
33 34 35 |
# File 'lib/bcp47/subtag.rb', line 33 def self.default find(self::DEFAULT_CODE) end |
.find(code) ⇒ Object
29 30 31 |
# File 'lib/bcp47/subtag.rb', line 29 def self.find(code) all.find {|subtag| subtag.code == code } end |
Instance Method Details
#==(object) ⇒ Object
9 10 11 |
# File 'lib/bcp47/subtag.rb', line 9 def ==(object) code == object.code end |
#full_name ⇒ Object
17 18 19 |
# File 'lib/bcp47/subtag.rb', line 17 def full_name "#{code} - #{name}" end |
#name ⇒ Object
13 14 15 |
# File 'lib/bcp47/subtag.rb', line 13 def name I18n.t(code, scope: i18n_scope) end |