Class: Refinery::CartItem

Inherits:
Object
  • Object
show all
Defined in:
lib/refinery/cart_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product) ⇒ CartItem

Returns a new instance of CartItem.



9
10
11
12
# File 'lib/refinery/cart_item.rb', line 9

def initialize(product)
  @product = product
  @quantity = 1
end

Instance Attribute Details

#productObject (readonly)

Returns the value of attribute product.



7
8
9
# File 'lib/refinery/cart_item.rb', line 7

def product
  @product
end

#quantityObject (readonly)

Returns the value of attribute quantity.



7
8
9
# File 'lib/refinery/cart_item.rb', line 7

def quantity
  @quantity
end

Instance Method Details

#increment_quantityObject



14
15
16
# File 'lib/refinery/cart_item.rb', line 14

def increment_quantity
  @quantity += 1
end

#nameObject



18
19
20
# File 'lib/refinery/cart_item.rb', line 18

def name
  @product.name
end

#priceObject



22
23
24
# File 'lib/refinery/cart_item.rb', line 22

def price
  @product.price * @quantity
end