8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/roxml/attribute_initializable.rb', line 8
def initialize_with_attributes(attributes={})
initialize_without_attributes()
return unless attributes.respond_to?(:each)
attributes.each do |attr, value|
roxml_attr = self.class.roxml_attrs.find { |r| r.attr_name == attr.to_s.chomp('?') }
if roxml_attr && sought_type = roxml_attr.sought_type
value = case sought_type
when :text then value
else
unless roxml_attr.array?
sought_type.new(value)
else
value.map { |v| sought_type.new(v) }
end if value
end
self.send(roxml_attr.setter, value)
elsif self.respond_to?(:"#{attr}=")
self.send(:"#{attr}=", value)
end
end
end
|