class Basket
Attributes
items[RW]
Public Class Methods
new()
click to toggle source
# File lib/wunder/basket.rb, line 7 def initialize @items = ItemCollection.new end
Public Instance Methods
add_item(product)
click to toggle source
# File lib/wunder/basket.rb, line 11 def add_item(product) item = items.find_product(product.product_code) if item.nil? items.push(BasketItem.new(product)) else item.increment_item_quantity end end
items_in_basket()
click to toggle source
# File lib/wunder/basket.rb, line 30 def items_in_basket products = [] items.each do |item| products << "#{item.product.product_code} - #{item.product.name}" end products.join(" , ") end
remove_item(product)
click to toggle source
# File lib/wunder/basket.rb, line 20 def remove_item(product) item = items.find_product(product.product_code) return if item.nil? if item.quantity == 1 items.delete(item) else item.decrement_item_quantity end end