Class: Hola::Cart
- Inherits:
-
Object
- Object
- Hola::Cart
- Defined in:
- lib/hola/cart.rb,
lib/hola/cart/item.rb,
lib/hola/cart/renderer.rb,
lib/hola/cart/item/processor.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #add(product_id:, quantity:) ⇒ Object
-
#initialize ⇒ Cart
constructor
A new instance of Cart.
- #output ⇒ Object
- #total ⇒ Object
Constructor Details
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
10 11 12 |
# File 'lib/hola/cart.rb', line 10 def items @items end |
Instance Method Details
#add(product_id:, quantity:) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/hola/cart.rb', line 16 def add(product_id:, quantity:) items[product_id] = Cart::Item::Processor.new( product_id: product_id, quantity: items[product_id].quantity + quantity ).perform end |
#output ⇒ Object
27 28 29 |
# File 'lib/hola/cart.rb', line 27 def output items.map { |_k, item| item.output } end |
#total ⇒ Object
23 24 25 |
# File 'lib/hola/cart.rb', line 23 def total items.sum { |_k, item| item.subtotal } end |