Class: Afterpay::Item
- Inherits:
-
Object
- Object
- Afterpay::Item
- Defined in:
- lib/afterpay/item.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#price ⇒ Object
Returns the value of attribute price.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#sku ⇒ Object
Returns the value of attribute sku.
Class Method Summary collapse
-
.from_response(response) ⇒ Object
Builds Item from response.
Instance Method Summary collapse
-
#initialize(name:, price:, sku: nil, quantity: 1) ⇒ Item
constructor
A new instance of Item.
- #to_hash ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def name @name end |
#price ⇒ Object
Returns the value of attribute price.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def price @price end |
#quantity ⇒ Object
Returns the value of attribute quantity.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def quantity @quantity end |
#sku ⇒ Object
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_hash ⇒ Object
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 |