1  #---
   2  # Excerpted from "Agile Web Development with Rails, 3rd Ed.",
   3  # published by The Pragmatic Bookshelf.
   4  # Copyrights apply to this code. It may not be used to create training material, 
   5  # courses, books, articles, and the like. Contact us if you are in doubt.
   6  # We make no guarantees that this code is fit for any purpose. 
   7  # Visit http://www.pragmaticprogrammer.com/titles/rails3 for more book information.
   8  #---
   9  class CartItem
  10 
  11    attr_reader :product, :quantity
  12    
  13    def initialize(product)
  14      @product = product
  15      @quantity = 1
  16    end
  17    
  18    def increment_quantity
  19      @quantity += 1
  20    end
  21    
  22    def title
  23      @product.title
  24    end
  25    
  26    def price
  27      @product.price * @quantity
  28    end
  29  end