79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/json_mapper.rb', line 79
def parse_json(json)
self.json_data = json
instance = new
attributes.each do |attribute|
if attribute.is_a?(AttributeList)
instance.send("#{attribute.name}=", attribute.dup)
end
end
attributes.each do |attribute|
if is_mapped?(attribute, json)
value = mapping_value(attribute, json)
if attribute.is_a?(AttributeList)
value = [ value ] unless value.is_a?(Array)
value.each do |v|
list_attribute = build_attribute(attribute.name, attribute.type, attribute.options)
list_attribute_value = list_attribute.typecast(v)
if list_attribute_value.is_a?(Array)
instance.send("#{attribute.name}").concat(list_attribute_value)
else
instance.send("#{attribute.name}") << list_attribute_value
end
end
else
instance.send("#{attribute.name}=".to_sym, attribute.typecast(value))
end
end
end
instance
end
|