Class: InventoryRefresh::InventoryCollection::Serialization

Inherits:
Object
  • Object
show all
Defined in:
lib/inventory_refresh/inventory_collection/serialization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inventory_collection) ⇒ Serialization

Returns a new instance of Serialization.

Parameters:



18
19
20
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 18

def initialize(inventory_collection)
  @inventory_collection = inventory_collection
end

Instance Attribute Details

#inventory_collectionObject (readonly)

Returns the value of attribute inventory_collection.



14
15
16
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 14

def inventory_collection
  @inventory_collection
end

Instance Method Details

#from_hash(inventory_objects_data, available_inventory_collections) ⇒ Object

Loads InventoryCollection data from it’s serialized form into existing InventoryCollection object

Parameters:

  • inventory_objects_data (Hash)

    Serialized InventoryCollection as Hash

  • available_inventory_collections (Array<InventoryRefresh::InventoryCollection>)

    List of available InventoryCollection objects



27
28
29
30
31
32
33
34
35
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 27

def from_hash(inventory_objects_data, available_inventory_collections)
  (inventory_objects_data['data'] || []).each do |inventory_object_data|
    build(hash_to_data(inventory_object_data, available_inventory_collections).symbolize_keys!)
  end

  (inventory_objects_data['partial_data'] || []).each do |inventory_object_data|
    skeletal_primary_index.build(hash_to_data(inventory_object_data, available_inventory_collections).symbolize_keys!)
  end
end

#sweep_scope_from_hash(sweep_scope, available_inventory_collections) ⇒ Object



37
38
39
40
41
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 37

def sweep_scope_from_hash(sweep_scope, available_inventory_collections)
  sweep_scope.map do |s|
    hash_to_data(s, available_inventory_collections).symbolize_keys!
  end
end

#sweep_scope_to_hash(sweep_scope) ⇒ Object



54
55
56
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 54

def sweep_scope_to_hash(sweep_scope)
  sweep_scope.map { |x| data_to_hash(x) }
end

#to_hashHash

Serializes InventoryCollection’s data storage into Array of Hashes

Returns:

  • (Hash)

    Serialized InventoryCollection object into Hash



46
47
48
49
50
51
52
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 46

def to_hash
  {
    :name              => name,
    :data              => data.map { |x| data_to_hash(x.data) },
    :partial_data      => skeletal_primary_index.index_data.map { |x| data_to_hash(x.data) },
  }
end