Class: Refinery::CartItem
- Inherits:
-
Object
- Object
- Refinery::CartItem
- Defined in:
- lib/refinery/cart_item.rb
Instance Attribute Summary collapse
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
Instance Method Summary collapse
- #increment_quantity ⇒ Object
-
#initialize(product) ⇒ CartItem
constructor
A new instance of CartItem.
- #name ⇒ Object
- #price ⇒ Object
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
#product ⇒ Object (readonly)
Returns the value of attribute product.
7 8 9 |
# File 'lib/refinery/cart_item.rb', line 7 def product @product end |
#quantity ⇒ Object (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_quantity ⇒ Object
14 15 16 |
# File 'lib/refinery/cart_item.rb', line 14 def increment_quantity @quantity += 1 end |
#name ⇒ Object
18 19 20 |
# File 'lib/refinery/cart_item.rb', line 18 def name @product.name end |
#price ⇒ Object
22 23 24 |
# File 'lib/refinery/cart_item.rb', line 22 def price @product.price * @quantity end |