Class: Afterpay::Item

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, price:, sku: nil, quantity: 1) ⇒ Item

Returns a new instance of Item.



9
10
11
12
13
14
# File 'lib/afterpay/item.rb', line 9

def initialize(name:, price:, sku: nil, quantity: 1)
  @name = name
  @sku = sku
  @quantity = quantity
  @price = price
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def name
  @name
end

#priceObject

Returns the value of attribute price.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def price
  @price
end

#quantityObject

Returns the value of attribute quantity.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def quantity
  @quantity
end

#skuObject

Returns the value of attribute sku.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def sku
  @sku
end

Class Method Details

.from_response(response) ⇒ Object

Builds Item from response



29
30
31
32
33
34
35
36
37
38
# File 'lib/afterpay/item.rb', line 29

def self.from_response(response)
  return nil if response.nil?

  new(
    name: response[:name],
    sku: response[:sku],
    quantity: response[:quantity],
    price: Utils::Money.from_response(response[:price])
  )
end

Instance Method Details

#to_hashObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/afterpay/item.rb', line 16

def to_hash
  {
    name: name,
    sku: sku,
    quantity: quantity,
    price: {
      amount: price.to_f,
      currency: price.currency
    }
  }
end