Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created June 14, 2012 02:49
Show Gist options
  • Save djberg96/2927789 to your computer and use it in GitHub Desktop.
Save djberg96/2927789 to your computer and use it in GitHub Desktop.
svg_parse attempt
require 'nokogiri'
file = 'world_map.svg'
tree = Nokogiri::XML(File.open(file))
str = "var #{File.basename(file, '.svg')} = {\n shapes: {"
tree.search('g/g').each do |gs|
str << "\n " << gs.attributes['id'].value + ': '
gs.search('path').each{ |paths|
str << '"' + paths[:d].tr(' ', '')
}
str << '"'
end
str << "\n }\n}\n"
puts str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment