Class: OSDb::Language
- Inherits:
-
Object
- Object
- OSDb::Language
- Defined in:
- lib/osdb/language.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#to_iso639_1 ⇒ Object
readonly
Returns the value of attribute to_iso639_1.
-
#to_iso639_2b ⇒ Object
readonly
Returns the value of attribute to_iso639_2b.
-
#to_locale ⇒ Object
readonly
Returns the value of attribute to_locale.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Language
constructor
A new instance of Language.
Constructor Details
#initialize(hash) ⇒ Language
Returns a new instance of Language.
75 76 77 78 79 80 |
# File 'lib/osdb/language.rb', line 75 def initialize(hash) @name = hash[:name] @to_iso639_1 = hash[:iso639_1] @to_iso639_2b = hash[:iso639_2b] @to_locale = hash[:locale] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
73 74 75 |
# File 'lib/osdb/language.rb', line 73 def name @name end |
#to_iso639_1 ⇒ Object (readonly)
Returns the value of attribute to_iso639_1.
73 74 75 |
# File 'lib/osdb/language.rb', line 73 def to_iso639_1 @to_iso639_1 end |
#to_iso639_2b ⇒ Object (readonly)
Returns the value of attribute to_iso639_2b.
73 74 75 |
# File 'lib/osdb/language.rb', line 73 def to_iso639_2b @to_iso639_2b end |
#to_locale ⇒ Object (readonly)
Returns the value of attribute to_locale.
73 74 75 |
# File 'lib/osdb/language.rb', line 73 def to_locale @to_locale end |
Class Method Details
.from_iso639_2b(code) ⇒ Object
67 68 69 |
# File 'lib/osdb/language.rb', line 67 def from_iso639_2b(code) new(LANGUAGES.find{ |lang| lang[:iso639_2b] == code }) end |
.from_locale(locale) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/osdb/language.rb', line 60 def from_locale(locale) locale = locale.split('.').first lang = LANGUAGES.find{ |lang| lang[:locale] == locale } return from_locale(locale.split('_').first) if !lang && locale.include?('_') new(lang) end |