Class: Natsukantou::LanguageCode

Inherits:
Object
  • Object
show all
Defined in:
lib/natsukantou/utility/language_code.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



14
15
16
# File 'lib/natsukantou/utility/language_code.rb', line 14

def code
  @code
end

#mainObject (readonly)

Returns the value of attribute main.



14
15
16
# File 'lib/natsukantou/utility/language_code.rb', line 14

def main
  @main
end

#subObject (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

Returns:

  • (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