lib/tasks/phonelib_tasks.rake in phonelib-0.2.9 vs lib/tasks/phonelib_tasks.rake in phonelib-0.3.0
- old
+ new
@@ -14,21 +14,22 @@
require 'nokogiri'
# get metadata from google
url = 'http://libphonenumber.googlecode.com/svn/trunk/resources/PhoneNumberMetadata.xml'
xml_data = Net::HTTP.get_response(URI.parse(url)).body
+ xml_data.force_encoding("utf-8")
# save in file for debug
File.open('data/PhoneNumberMetaData.xml', 'w+') do |f|
f.write(xml_data)
end
# start parsing
doc = Nokogiri::XML(xml_data)
main = doc.elements.first.elements.first
- countries = []
+ countries = {}
main.elements.each do |el|
# each country
country = {}
el.attributes.each do |k, v|
country[camel2snake(k).to_sym] = v.to_s.tr(" \n", '')
@@ -69,10 +70,10 @@
end
end
end
- countries.push(country)
+ countries[country[:id]] = country
end
File.open('data/phone_data.dat', 'wb+') do |f|
Marshal.dump(countries, f)
end
end