lib/happymapper.rb in happymapper-0.1.6 vs lib/happymapper.rb in happymapper-0.1.7
- old
+ new
@@ -97,34 +97,44 @@
private
def create_collection(nodes, namespace=nil)
nodes.inject([]) do |acc, el|
obj = new
- attributes.each { |attr| obj.send("#{attr.name}=", attr.from_xml_node(el)) }
- elements.each { |elem| obj.send("#{elem.name}=", elem.from_xml_node(el, namespace)) }
+ attributes.each { |attr| obj.send("#{normalize_name attr.name}=", attr.from_xml_node(el)) }
+ elements.each { |elem| obj.send("#{normalize_name elem.name}=", elem.from_xml_node(el, namespace)) }
acc << obj
end
end
def create_getter(name)
+ name = normalize_name(name)
+
class_eval <<-EOS, __FILE__, __LINE__
def #{name}
@#{name}
end
EOS
end
def create_setter(name)
+ name = normalize_name(name)
+
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(value)
@#{name} = value
end
EOS
end
def create_accessor(name)
+ name = normalize_name(name)
+
create_getter(name)
create_setter(name)
+ end
+
+ def normalize_name(name)
+ name.gsub('-', '_')
end
end
end
require 'happymapper/item'