Class: Pyper::Pipes::Model::AttributeDeserializer
- Inherits:
-
Struct
- Object
- Struct
- Pyper::Pipes::Model::AttributeDeserializer
- Defined in:
- lib/pyper/pipes/model/attribute_deserializer.rb
Overview
to these types.
Instance Attribute Summary collapse
-
#type_mapping ⇒ Object
Returns the value of attribute type_mapping.
Instance Method Summary collapse
- #deserialize(value, type) ⇒ Object
-
#pipe(items, status = {}) ⇒ Enumerable<Hash>
A list of items, deserialized according to the type mapping.
Instance Attribute Details
#type_mapping ⇒ Object
Returns the value of attribute type_mapping
6 7 8 |
# File 'lib/pyper/pipes/model/attribute_deserializer.rb', line 6 def type_mapping @type_mapping end |
Instance Method Details
#deserialize(value, type) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/pyper/pipes/model/attribute_deserializer.rb', line 20 def deserialize(value, type) if (type == Array) || (type == Hash) then JSON.parse(value) elsif (type == Integer) then value.to_i elsif (type == Float) then value.to_f else value end end |
#pipe(items, status = {}) ⇒ Enumerable<Hash>
Returns A list of items, deserialized according to the type mapping.
10 11 12 13 14 15 16 17 18 |
# File 'lib/pyper/pipes/model/attribute_deserializer.rb', line 10 def pipe(items, status = {}) items.map do |item| new_item = item.dup type_mapping.each do |field, type| new_item[field] = deserialize(new_item[field], type) if new_item[field] end new_item end end |