Skip to content

Instantly share code, notes, and snippets.

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)
@davidcsi
davidcsi / gist:4695aa9a18ff4f05857d10b4823763f9
Created December 19, 2017 23:08
ruby, print when the current element is the last one.
puts doc.xpath('//*[not(*)][text()]').map{
|n|
if is_number?(n.text)
"'#{n.parent.name}.#{n.name}': #{n.text}"
else
"'#{n.parent.name}.#{n.name}': '#{n.text}'"
end
}