class ISO3166::Country

Attributes

xml_node[R]

Public Class Methods

[](code) click to toggle source
# File lib/iso3166/country.rb, line 29
def self.[](code)
  new(code)
end
all() click to toggle source
# File lib/iso3166/country.rb, line 33
def self.all
  ISO3166::XMLData.all_names_with_codes.map do |name, alpha2|
    new(alpha2)
  end
end
all_names_with_codes() click to toggle source
# File lib/iso3166/country.rb, line 25
def self.all_names_with_codes
  ISO3166::XMLData.all_names_with_codes
end
find_by(alpha2: nil, alpha3: nil) click to toggle source
# File lib/iso3166/country.rb, line 15
def self.find_by(alpha2: nil, alpha3: nil)
  raise TooManyArguments, "submit either alpha2 or alpha3" if alpha2 && alpha3

  if alpha2
    new(alpha2)
  elsif alpha3 && (xml_node = ISO3166::XMLData.find_by_alpha3(alpha3))
    new(nil, xml_node: xml_node)
  end
end
new(code, xml_node: nil) click to toggle source
Calls superclass method
# File lib/iso3166/country.rb, line 7
def self.new(code, xml_node: nil)
  return super(xml_node) if xml_node

  if (xml_node = ISO3166::XMLData.find(code))
    super(xml_node)
  end
end
new(xml_node) click to toggle source
# File lib/iso3166/country.rb, line 41
def initialize(xml_node)
  @xml_node = xml_node
end

Public Instance Methods

==(other) click to toggle source
# File lib/iso3166/country.rb, line 89
def ==(other)
  other.respond_to?(:alpha2) && other.alpha2 == alpha2
end
Also aliased as: eql?
alpha2() click to toggle source
# File lib/iso3166/country.rb, line 45
def alpha2
  @_alpha2 ||= xml_node.at_xpath("./alpha-2-code").text
end
alpha3() click to toggle source
# File lib/iso3166/country.rb, line 49
def alpha3
  @_alpha3 ||= xml_node.at_xpath("./alpha-3-code").text
end
currency_code() click to toggle source
# File lib/iso3166/country.rb, line 85
def currency_code
  @_currency_code ||= yml_data["currency_code"]
end
eql?(other)
Alias for: ==
full_name() click to toggle source
# File lib/iso3166/country.rb, line 57
def full_name
  @_full_name ||= xml_node.at_xpath("./full-name[@lang3code='eng']").text
end
in_eu?() click to toggle source
# File lib/iso3166/country.rb, line 69
def in_eu?
  !!yml_data["eu_member"]
end
name() click to toggle source
# File lib/iso3166/country.rb, line 53
def name
  @_name ||= xml_node.at_xpath("./short-name[@lang3code='eng']").text
end
number() click to toggle source
# File lib/iso3166/country.rb, line 65
def number
  @_number ||= xml_node.at_xpath("./numeric-code").text
end
postal_code_format() click to toggle source
# File lib/iso3166/country.rb, line 73
def postal_code_format
  yml_data["postal_code_format"]
end
postal_code_regexp() click to toggle source
# File lib/iso3166/country.rb, line 77
def postal_code_regexp
  yml_data["postal_code_regexp"]
end
translation() click to toggle source
# File lib/iso3166/country.rb, line 61
def translation
  @_translation ||= name.sub(" (the)", "")
end
yml_data() click to toggle source
# File lib/iso3166/country.rb, line 81
def yml_data
  @_yml_data ||= ISO3166::YMLData.find(alpha2) || {}
end