lib/xmlhasher/node.rb in xmlhasher-0.0.2 vs lib/xmlhasher/node.rb in xmlhasher-0.0.3

- old
+ new

@@ -11,23 +11,22 @@ def to_hash h = {} if text 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] = child.to_hash + h[name].merge!(child.to_hash) else if children.map(&:name).uniq.size == 1 - h[name] = children.inject({}) { |r, child| (r[child.name] ||= []) << child.to_hash[child.name]; r } + h[name].merge!(children.inject({}) { |r, child| (r[child.name] ||= []) << child.to_hash[child.name]; r }) else - h[name] = children.inject({}) { |r, child| r.merge!(child.to_hash); r } + h[name].merge!(children.inject({}) { |r, child| r.merge!(child.to_hash); r }) end end end - attributes.each do |key, value| - h[key] = value if value - end + h[name] = nil if h[name].empty? h end end end