Class: Sources::CLDR::Subdivision

Inherits:
Object
  • Object
show all
Defined in:
lib/countries/sources/cldr/subdivision.rb

Overview

Auxiliary Subdivision class to support loading Unicode CLDR data to update local files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language_code:, xml:) ⇒ Subdivision

Returns a new instance of Subdivision.



9
10
11
12
# File 'lib/countries/sources/cldr/subdivision.rb', line 9

def initialize(language_code:, xml:)
  @language_code = language_code
  @xml = xml
end

Instance Attribute Details

#language_codeObject (readonly)

Returns the value of attribute language_code.



7
8
9
# File 'lib/countries/sources/cldr/subdivision.rb', line 7

def language_code
  @language_code
end

#xmlObject (readonly)

Returns the value of attribute xml.



7
8
9
# File 'lib/countries/sources/cldr/subdivision.rb', line 7

def xml
  @xml
end

Instance Method Details

#codeObject



22
23
24
# File 'lib/countries/sources/cldr/subdivision.rb', line 22

def code
  type[2..].upcase
end

#country_codeObject



18
19
20
# File 'lib/countries/sources/cldr/subdivision.rb', line 18

def country_code
  type[0..1].upcase
end

#textObject



14
15
16
# File 'lib/countries/sources/cldr/subdivision.rb', line 14

def text
  xml.text
end

#to_hObject



30
31
32
33
34
35
# File 'lib/countries/sources/cldr/subdivision.rb', line 30

def to_h
  data = {}
  data['translations'] ||= {}
  data['translations'][language_code] = text
  data
end

#typeObject



26
27
28
# File 'lib/countries/sources/cldr/subdivision.rb', line 26

def type
  xml.attributes['type'].value.delete('-')
end