35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/xmlmapping.rb', line 35
def initialize(input)
root = parse(input)
mappings = self.class.mappings
raw_mappings = self.class.raw_mappings
raw_mappings.values.select { |mapping| mapping[:cardinality] == :many }.each { |m|
instance_variable_set("@#{m[:attribute]}", [])
}
raw_mappings.values.select { |mapping| mapping.has_key? :default }.each { |m|
instance_variable_set("@#{m[:attribute]}", m[:default])
}
root.each_element { |e|
process(e, mappings[:element])
}
root.attributes.each_attribute { |a|
process(a, mappings[:attribute])
}
mappings[:text].values.each { |mapping|
name = mapping[:attribute]
value = (root, mapping)
instance_variable_set("@#{name}", value)
}
end
|