Class: Natsukantou::LanguageCode
- Inherits:
-
Object
- Object
- Natsukantou::LanguageCode
- Defined in:
- lib/natsukantou/utility/language_code.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
Instance Method Summary collapse
-
#initialize(code) ⇒ LanguageCode
constructor
A new instance of LanguageCode.
- #is?(other) ⇒ Boolean
Constructor Details
#initialize(code) ⇒ LanguageCode
Returns a new instance of LanguageCode.
5 6 7 8 9 10 11 12 |
# File 'lib/natsukantou/utility/language_code.rb', line 5 def initialize(code) @code = code.downcase @main, @sub = @code.split('-') if @main.length != 2 raise 'Language code should be in the form of xx or xx-yy' end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
14 15 16 |
# File 'lib/natsukantou/utility/language_code.rb', line 14 def code @code end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
14 15 16 |
# File 'lib/natsukantou/utility/language_code.rb', line 14 def main @main end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
14 15 16 |
# File 'lib/natsukantou/utility/language_code.rb', line 14 def sub @sub end |
Instance Method Details
#is?(other) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/natsukantou/utility/language_code.rb', line 16 def is?(other) if !other.is_a?(self.class) other = self.class.new(other) end return false if other.main != main return true if other.sub.nil? sub ? other.sub == sub : false end |