Created
June 14, 2012 02:49
-
-
Save djberg96/2927789 to your computer and use it in GitHub Desktop.
svg_parse attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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