Class: CartItem
- Inherits:
-
Object
- Object
- CartItem
- Defined in:
- lib/cart_item.rb
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
Instance Method Summary collapse
- #decrease_quantity ⇒ Object
- #increment_quantity ⇒ Object
-
#initialize(item) ⇒ CartItem
constructor
A new instance of CartItem.
- #to_cents ⇒ Object
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
#item ⇒ Object (readonly)
Returns the value of attribute item.
2 3 4 |
# File 'lib/cart_item.rb', line 2 def item @item end |
#quantity ⇒ Object (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_quantity ⇒ Object
13 14 15 |
# File 'lib/cart_item.rb', line 13 def decrease_quantity @quantity -= 1 end |
#increment_quantity ⇒ Object
9 10 11 |
# File 'lib/cart_item.rb', line 9 def increment_quantity @quantity += 1 end |
#to_cents ⇒ Object
17 18 19 |
# File 'lib/cart_item.rb', line 17 def to_cents (self.item.price * 100).round end |