Class: CartItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ CartItem

Returns a new instance of CartItem.



4
5
6
7
# File 'lib/cart_item.rb', line 4

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

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



2
3
4
# File 'lib/cart_item.rb', line 2

def item
  @item
end

#quantityObject (readonly)

Returns the value of attribute quantity.



2
3
4
# File 'lib/cart_item.rb', line 2

def quantity
  @quantity
end

Instance Method Details

#decrease_quantityObject



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

def decrease_quantity
  @quantity -= 1
end

#increment_quantityObject



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

def increment_quantity
  @quantity += 1
end

#to_centsObject



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

def to_cents
  (self.item.price * 100).round
end