Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Created January 12, 2015 16:24
Show Gist options
  • Save ripienaar/9ce649d9cacab76b7ae8 to your computer and use it in GitHub Desktop.
Save ripienaar/9ce649d9cacab76b7ae8 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'xmlsimple'
require 'yaml'
require 'pp'
hash = XmlSimple.xml_in('togo.xml')
points = {}
hash["point"].each do |p|
point = {}
p.keys.each do |k|
point[k.intern] = p[k][0]
end
point[:type] = point[:type].intern
point[:type] = :visit
point[:lon] = point.delete(:long)
points[ point[:country] ] ||= {:points => []}
points[ point[:country] ][:points] << point
end
points.each do |country, data|
fname = country.gsub(" ", "_").downcase
open("%s.yaml" % fname, "w") do |f|
f.puts YAML.dump(data)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment