Module: ISO3166::SubdivisionMethods

Included in:
Data
Defined in:
lib/countries/data/subdivision_methods.rb

Instance Method Summary collapse

Instance Method Details

#create_subdivisions(subdivision_data) ⇒ Object



24
25
26
27
28
# File 'lib/countries/data/subdivision_methods.rb', line 24

def create_subdivisions(subdivision_data)
  subdivision_data.transform_values do |subdivision|
    Subdivision.new(subdivision)
  end
end

#load_data_for_alpha2(alpha2) ⇒ Object



14
15
16
17
# File 'lib/countries/data/subdivision_methods.rb', line 14

def load_data_for_alpha2(alpha2)
  file = subdivision_file_path(alpha2)
  File.exist?(file) ? YAML.load_file(file) : {}
end

#subdivision_data(alpha2) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/countries/data/subdivision_methods.rb', line 5

def subdivision_data(alpha2)
  data = load_data_for_alpha2(alpha2)
  locales = ISO3166.configuration.locales.map(&:to_s)

  data.each_value { |subdivision| subdivision['translations'] = subdivision['translations'].slice(*locales) }

  data
end

#subdivisions(alpha2) ⇒ Object



19
20
21
22
# File 'lib/countries/data/subdivision_methods.rb', line 19

def subdivisions(alpha2)
  @subdivisions ||= {}
  @subdivisions[alpha2] ||= create_subdivisions(subdivision_data(alpha2))
end