lib/xmlhasher/node.rb in xmlhasher-1.0.2 vs lib/xmlhasher/node.rb in xmlhasher-1.0.3
- old
+ new
@@ -13,11 +13,10 @@
if text && !text.empty?
h[name] = text
else
h[name] = attributes.inject({}) { |r, (key, value)| r[key] = value if !value.nil? && !value.to_s.empty?; r }
if children.size == 1
- child = children.first
- h[name].merge!(child.to_hash)
+ h[name].merge!(children.first.to_hash)
else
h[name].merge!(children.group_by { |child| child.name }.inject({}) { |r, (k, v)| v.length == 1 ? r.merge!(v.first.to_hash) : r[k] = v.map { |c| c.to_hash[c.name] }; r })
end
end
h[name] = nil if h[name].empty?