End chapter 8
[depot.git] / app / models / cart_item.rb
diff --git a/app/models/cart_item.rb b/app/models/cart_item.rb
new file mode 100644 (file)
index 0000000..6924ed7
--- /dev/null
@@ -0,0 +1,21 @@
+class CartItem
+  attr_reader :product, :quantity
+  
+  def initialize(product)
+    @product = product
+    @quantity = 1
+  end
+  
+  def increment_quantity
+    @quantity += 1
+  end
+  
+  def title
+    @product.title
+  end
+  
+  def price
+    @product.price * @quantity
+  end
+  
+end