Module: CLLI::ISO3166::ClassMethods

Defined in:
lib/clli/iso3166.rb

Overview

These methods will be available in the CLLI class.

Instance Method Summary collapse

Instance Method Details

#country_name(region_code) ⇒ Object

Lookup the name of the country for the specified region_code.

Params:

region-code

the CLLI :region attribute value.



33
34
35
36
37
38
# File 'lib/clli/iso3166.rb', line 33

def country_name(region_code)
  country_code = iso_country(region_code)
  country = ::ISO3166::Country.new(country_code)
  return if country.nil?
  country.name
end

#iso_country(region_code) ⇒ Object

Convert the CLLI region code into an ISO 3166 country code.

Params:

region-code

the CLLI :region attribute value.



21
22
23
24
25
26
# File 'lib/clli/iso3166.rb', line 21

def iso_country(region_code)
  load_data
  return @region_conversion_data[region_code]['country'] if @region_conversion_data.key?(region_code)
  country = ::ISO3166::Country.new(region_code)
  country.nil? ? 'ZZ' : country.alpha2
end

#iso_state(region_code) ⇒ Object

Convert the CLLI region code into an ISO 3166 state code.

Params:

region-code

the CLLI :region attribute value.



45
46
47
48
# File 'lib/clli/iso3166.rb', line 45

def iso_state(region_code)
  load_data
  return @region_conversion_data[region_code]['state'] if @region_conversion_data.key?(region_code)
end

#state_name(region_code) ⇒ Object

Lookup the name of the state for the specified region_code.

Params:

region-code

the CLLI :region attribute value.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/clli/iso3166.rb', line 55

def state_name(region_code)
  state_code = iso_state(region_code)
  return unless state_code
  country_code = iso_country(region_code)
  return unless country_code
  country = ::ISO3166::Country.new(country_code)
  return unless country
  state_data = country.states[state_code]
  return unless state_data
  state_data['name']
end