Skip to content

Instantly share code, notes, and snippets.

@davidcsi
Created December 19, 2017 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcsi/4ad15f2342845d7a3093806ccbb1d2d4 to your computer and use it in GitHub Desktop.
Save davidcsi/4ad15f2342845d7a3093806ccbb1d2d4 to your computer and use it in GitHub Desktop.
final version
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