Class: ISO3166::XMLData
- Inherits:
-
Object
- Object
- ISO3166::XMLData
- Defined in:
- lib/iso3166/xml_data.rb
Constant Summary collapse
- @@semaphore =
Mutex.new
- @@data =
nil
Class Method Summary collapse
- .all_names_with_codes ⇒ Object
- .find(code) ⇒ Object
- .find_by_alpha3(code) ⇒ Object
- .reload! ⇒ Object
- .reset! ⇒ Object
Class Method Details
.all_names_with_codes ⇒ Object
31 32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
21 22 23 24 |
# File 'lib/iso3166/xml_data.rb', line 21 def find(code) reload! @@data.at_xpath("//country[@id='#{code}']") end |
.find_by_alpha3(code) ⇒ Object
26 27 28 29 |
# 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! ⇒ Object
13 14 15 16 17 18 19 |
# 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! ⇒ Object
9 10 11 |
# File 'lib/iso3166/xml_data.rb', line 9 def reset! @@data = nil end |