class ActiveUtils::Country
Constants
- COUNTRIES
- COUNTRIES_THAT_DO_NOT_USE_POSTALCODES
Attributes
Public Class Methods
Source
# File lib/active_utils/country.rb, line 332 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] == name } end raise InvalidCountryCodeError, "No country could be found for the country #{name}" if country.nil? Country.new(country.dup) end
Source
# File lib/active_utils/country.rb, line 42 def initialize(options = {}) requires!(options, :name, :alpha2, :alpha3) @name = options.delete(:name) @codes = options.collect{|k,v| CountryCode.new(v)} end
Public Instance Methods
Source
# File lib/active_utils/country.rb, line 52 def ==(other) (@name == other.name) end
Also aliased as: eql?
Source
# File lib/active_utils/country.rb, line 48 def code(format) @codes.detect{|c| c.format == format} end
Source
# File lib/active_utils/country.rb, line 328 def uses_postal_codes? !COUNTRIES_THAT_DO_NOT_USE_POSTALCODES.include?(code(:alpha2).value) end