Class: ISO::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/iso/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Tag

Returns a new instance of Tag.



5
6
7
8
9
# File 'lib/iso/tag.rb', line 5

def initialize(code)
  @code     = code
  @language = Language.identify(code)
  @region   = Region.identify(code) || UN::Region.identify(code)
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/iso/tag.rb', line 3

def language
  @language
end

#regionObject

Returns the value of attribute region.



3
4
5
# File 'lib/iso/tag.rb', line 3

def region
  @region
end

Instance Method Details

#codesObject



11
12
13
# File 'lib/iso/tag.rb', line 11

def codes
  subtags.map(&:code)
end

#subtagsObject



15
16
17
# File 'lib/iso/tag.rb', line 15

def subtags
  [language, region].compact
end

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/iso/tag.rb', line 19

def valid?
  return false if @language.nil?
  @code.split('-').size == subtags.size
end