class ActiveMerchant::Country

Constants

COUNTRIES

Attributes

name[R]

Public Class Methods

find(name) click to toggle source
# File lib/active_merchant/country.rb, line 323
def self.find(name)
  raise InvalidCountryCodeError, 'Cannot lookup country for an empty name' if name.blank?

  case name.length
  when 2, 3
    upcase_name = name.upcase
    country_code = CountryCode.new(name)
    country = COUNTRIES.detect { |c| c[country_code.format] == upcase_name }
  else
    country = COUNTRIES.detect { |c| c[:name].casecmp(name).zero? }
  end
  raise InvalidCountryCodeError, "No country could be found for the country #{name}" if country.nil?

  Country.new(country.dup)
end
new(options = {}) click to toggle source
# File lib/active_merchant/country.rb, line 41
def initialize(options = {})
  @name = options.delete(:name)
  @codes = options.collect { |_k, v| CountryCode.new(v) }
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method
# File lib/active_merchant/country.rb, line 50
def ==(other)
  if other.class == ActiveMerchant::Country
    (@name == other.name)
  else
    super
  end
end
Also aliased as: eql?
code(format) click to toggle source
# File lib/active_merchant/country.rb, line 46
def code(format)
  @codes.detect { |c| c.format == format }
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/active_merchant/country.rb, line 60
def hash
  @name.hash
end
to_s() click to toggle source
# File lib/active_merchant/country.rb, line 64
def to_s
  @name
end