lib/rock_rms/response/base.rb in rock_rms-7.4.0 vs lib/rock_rms/response/base.rb in rock_rms-8.0.0
- old
+ new
@@ -4,11 +4,13 @@
attr_reader :data
BASE_MAPPING = {
id: 'Id',
created_date_time: 'CreatedDateTime',
- modified_date_time: 'ModifiedDateTime'
+ modified_date_time: 'ModifiedDateTime',
+ attributes: 'Attributes',
+ attribute_values: 'AttributeValues'
}.freeze
def self.format(data)
new(data).format
end
@@ -29,11 +31,24 @@
return {} if data.nil?
dict
.merge(BASE_MAPPING)
.each_with_object({}) do |(l, r), object|
- object[l] = data[r]
+ if l == :attributes || l == :attribute_values
+ format_klass = l == :attributes ? Attribute : AttributeValue
+ object[l] = format_attributes(data[r], format_klass)
+ else
+ object[l] = data[r]
+ end
end
+ end
+
+ def format_attributes(res, klass)
+ return res if res.nil?
+
+ res.each_with_object({}) do |(attr, val), object|
+ object[attr] = klass.format(val)
+ end
end
end
end
end