Class: MusicTodayApiWrapper::Resources::Purchase::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/purchase/item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variant = Variant.new, quantity = 1, tax = nil, total = nil, destination_id = nil) ⇒ Item

Returns a new instance of Item.



10
11
12
13
14
15
16
17
# File 'lib/resources/purchase/item.rb', line 10

def initialize(variant = Variant.new, quantity = 1, tax = nil,
  total = nil, destination_id = nil)
  @variant = variant
  @quantity = quantity
  @tax = tax
  @total = total
  @destination_id = destination_id
end

Instance Attribute Details

#quantityObject

Returns the value of attribute quantity.



8
9
10
# File 'lib/resources/purchase/item.rb', line 8

def quantity
  @quantity
end

#variantObject

Returns the value of attribute variant.



8
9
10
# File 'lib/resources/purchase/item.rb', line 8

def variant
  @variant
end

Class Method Details

.from_hash(item_hash) ⇒ Object



29
30
31
32
33
# File 'lib/resources/purchase/item.rb', line 29

def self.from_hash(item_hash)
  variant = Variant.from_hash(item_hash)
  Item.new(variant, item_hash['quantity'], item_hash['tax'],
    item_hash['total'])
end

Instance Method Details

#as_hashObject



19
20
21
22
23
24
25
26
27
# File 'lib/resources/purchase/item.rb', line 19

def as_hash
  { sku: @variant.sku,
    qty: @quantity,
    quantity: @quantity,
    price: @variant.price,
    tax: @tax,
    total: @total,
    destIndex: @destination_id }.compact
end