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
|
# File 'lib/sepa/base.rb', line 15
def to_xml builder
self.class.attribute_defs.each do |name, meta|
item = self.send(name)
options = meta[:options] || { }
attributes = build_xml_attributes options[:attributes]
next if item == nil
if meta[:type] == :string
builder.__send__(meta[:tag], item, attributes)
elsif meta[:type] == :[]
if meta[:member_type] == nil
item.each { |obj| builder.__send__(meta[:tag], obj, attributes) }
else
item.each do |obj|
builder.__send__(meta[:tag], attributes) { obj.to_xml builder }
end
end
elsif meta[:type] == Time
v = item.is_a?(String) ? item : item.strftime("%Y-%m-%dT%H:%M:%S")
builder.__send__(meta[:tag], v, attributes)
elsif meta[:type] == Date
v = item.is_a?(String) ? item : item.strftime("%Y-%m-%d")
builder.__send__(meta[:tag], v, attributes)
elsif meta[:type].is_a? Class
builder.__send__(meta[:tag], attributes) { item.to_xml builder }
end
end
end
|