class Pyper::Pipes::Model::AttributeDeserializer
@param type_mapping [Hash<Symbol, Class>] A map from field names to types. fields will be deserialized according to these types.
Public Instance Methods
deserialize(value, type)
click to toggle source
# 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 = {})
click to toggle source
@param status [Hash] The mutable status field @return [Enumerable<Hash>] A list of items, deserialized according to the type mapping
# 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