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 demongoize(alpha2)

def demongoize(alpha2)
  new(alpha2)
end

def eql?(other)

def eql?(other)
  self == other
end

def evolve(country)

def evolve(country)
  mongoize(country)
end

def hash

def hash
  [alpha2, alpha3].hash
end

def in_eea?

def in_eea?
  data['eea_member'].nil? ? false : data['eea_member']
end

def in_esm?

def in_esm?
  data['esm_member'].nil? ? in_eea? : data['esm_member']
end

def in_eu?

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

def local_name
  @local_name ||= local_names.first
end

def local_names

TODO: Looping through locale langs could be be very slow across multiple countries
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)

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 start_of_week

def start_of_week
  data['start_of_week']
end

def subdivision_names_with_codes(locale = 'en')

def subdivision_names_with_codes(locale = 'en')
  subdivisions.map { |k, v| [v.translations[locale] || v.name, k] }
end

def subdivisions

def subdivisions
  @subdivisions ||= if data['subdivisions']
                      self.class.create_subdivisions(data['subdivisions'])
                    else
                      self.class.subdivisions(alpha2)
                    end
end

def subdivisions?

def subdivisions?
  !subdivisions.empty?
end

def to_s

def to_s
  data['name']
end

def translated_names

def translated_names
  data['translations'].values
end

def translation(locale = 'en')

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