class ISO3166::XMLData

Public Class Methods

all_names_with_codes() click to toggle source
# File lib/iso3166/xml_data.rb, line 31
def all_names_with_codes
  reload!
  @@data.xpath("//country[status[text()='officially-assigned']]").map do |xml_node|
    [
      xml_node.at_xpath("./short-name[@lang3code='eng']").text,
      xml_node.at_xpath("./alpha-2-code").text
    ]
  end
end
find(code) click to toggle source
# File lib/iso3166/xml_data.rb, line 21
def find(code)
  reload!
  @@data.at_xpath("//country[@id='#{code}']")
end
find_by_alpha3(code) click to toggle source
# File lib/iso3166/xml_data.rb, line 26
def find_by_alpha3(code)
  reload!
  @@data.at_xpath("//country[alpha-3-code[text()='#{code}']]")
end
reload!() click to toggle source
# File lib/iso3166/xml_data.rb, line 13
def reload!
  return if @@data

  @@semaphore.synchronize do
    @@data = File.open(ISO3166::Countries.data_path) { |f| Nokogiri::XML(f) }
  end
end
reset!() click to toggle source
# File lib/iso3166/xml_data.rb, line 9
def reset!
  @@data = nil
end