class ISO3166::Country

def <=>(other)

def <=>(other)
  to_s <=> other.to_s
end

def ==(other)

def ==(other)
  other.respond_to?(:alpha2) && other.alpha2 == alpha2
end

def common_name

Returns:
  • (String) - the “common name” of this Country in English.
def common_name
  ISO3166.configuration.locales = ISO3166.configuration.locales.append(:en).uniq
  translation('en')
end

def demongoize(alpha2)

Get the object as it was stored with Mongoid, and instantiate an +ISO3166::Country+.
def demongoize(alpha2)
  new(alpha2)
end

def eql?(other)

def eql?(other)
  self == other
end

def evolve(country)

Convert an +ISO3166::Country+ to the data that is stored by Mongoid.
def evolve(country)
  mongoize(country)
end

def hash

def hash
  [alpha2, alpha3].hash
end

def in_eea?

+true+ if this country is a member of the European Economic Area.
def in_eea?
  data['eea_member'].nil? ? false : data['eea_member']
end

def in_esm?

+true+ if this country is a member of the European Single Market.
def in_esm?
  data['esm_member'].nil? ? in_eea? : data['esm_member']
end

def in_eu?

+true+ if this country is a member of the European Union.
def in_eu?
  data['eu_member'].nil? ? false : data['eu_member']
end

def initialize(country_data)

def initialize(country_data)
  @country_data_or_code = country_data
  reload
end

def local_name

Returns:
  • (String) - The name for this Country, in this Country's locale.
def local_name
  @local_name ||= local_names.first
end

def local_names

Returns:
  • (Array) - TThe list of names for this Country, in this Country's locales.
def local_names
  ISO3166.configuration.locales = (ISO3166.configuration.locales + languages.map(&:to_sym)).uniq
  reload
  @local_names ||= languages.map { |language| translations[language] }
end

def mongoize

def mongoize
  ISO3166::Country.mongoize(self)
end

def mongoize(country)

Convert an +ISO3166::Country+ to the data that is stored by Mongoid.
def mongoize(country)
  if country.is_a?(self) && !country.data.nil?
    country.alpha2
  elsif send(:valid_alpha2?, country)
    new(country).alpha2
  end
end

def reload

def reload
  @data = if @country_data_or_code.is_a?(Hash)
            @country_data_or_code
          else
            ISO3166::Data.new(@country_data_or_code).call
          end
end

def subdivision_names_with_codes(locale = 'en')

Returns:
  • (Array) - This Country's subdivision pairs of names and codes.

Parameters:
  • locale (String) -- The locale to use for translations.
def subdivision_names_with_codes(locale = 'en')
  subdivisions.map { |k, v| [v.translations[locale] || v.name, k] }
end

def subdivisions

Returns:
  • (Array) - the list of subdivisions for this Country.
def subdivisions
  @subdivisions ||= if data['subdivisions']
                      self.class.create_subdivisions(data['subdivisions'])
                    else
                      self.class.subdivisions(alpha2)
                    end
end

def subdivisions?

+true+ if this Country has any Subdivisions.
def subdivisions?
  !subdivisions.empty?
end

def to_s

def to_s
  data['iso_short_name']
end

def translated_names

Returns:
  • (Array) - the list of names for this Country in all loaded locales.
def translated_names
  data['translations'].values
end

def translation(locale = 'en')

Returns:
  • (String) - the name of this Country in the selected locale.

Parameters:
  • locale (String) -- The locale to use for translations.
def translation(locale = 'en')
  data['translations'][locale.to_s.downcase]
end

def valid?

def valid?
  !(data.nil? || data.empty?)
end

def valid_alpha2?(country)

def valid_alpha2?(country)
  country.is_a?(String) && !ISO3166::Country.new(country).nil?
end