Created
December 19, 2017 23:21
-
-
Save davidcsi/4ad15f2342845d7a3093806ccbb1d2d4 to your computer and use it in GitHub Desktop.
final version
This file contains 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
comma = "" | |
last_index = doc.xpath('//*[not(*)][text()]').size.pred | |
puts doc.xpath('//*[not(*)][text()]').map.with_index{ |n,i| | |
if i == last_index | |
comma = "" | |
else | |
comma = "," | |
end | |
if is_number?(n.text) | |
"'#{n.parent.name}.#{n.name}': #{n.text}" + comma | |
else | |
"'#{n.parent.name}.#{n.name}': '#{n.text}'" + comma | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment