Class: Pyper::Pipes::Model::AttributeDeserializer

Inherits:
Struct
  • Object
show all
Defined in:
lib/pyper/pipes/model/attribute_deserializer.rb

Overview

to these types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#type_mappingObject

Returns the value of attribute type_mapping

Returns:

  • (Object)

    the current value of 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.

Parameters:

  • items (Enumerable<Hash>)

    A list of items

  • status (Hash) (defaults to: {})

    The mutable status field

Returns:

  • (Enumerable<Hash>)

    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