14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/roundtrip_xml/dsl_builder.rb', line 14
def write_attrs(clazz, xml, inset='')
clazz.roxml_attrs.inject('') do |out, attr|
return '' unless xml
accessor = attr.accessor
selector = attr.name
if attr.sought_type == :text
text_element = xml.children.find {|c| c.name == selector}
out += inset + "#{accessor} '#{text_element.content}'\n" if text_element
elsif attr.sought_type == :attr
child_attribute = xml.attributes[selector]
out += inset + "#{accessor} '#{child_attribute.content}'\n" if child_attribute
elsif !attr.array?
child_element = xml.children.find {|c| c.name == selector}
if child_element
out += inset + "#{accessor} do\n#{write_attrs attr.sought_type, child_element, inset + ' '}#{inset}end\n"
end
else
xml.xpath(selector).each do |node|
out += inset + "#{accessor} do\n#{write_attrs attr.sought_type, node, inset + ' '}#{inset}end\n"
if inset == ''
out += "\n"
end
end
end
out
end
end
|