Sha256: 94f80d3e04f1090acf4f1f7a2a357c0eb84c74335e25ecc00ab547f4d9874fff
Contents?: true
Size: 721 Bytes
Versions: 3
Compression:
Stored size: 721 Bytes
Contents
#--- # Excerpted from "Agile Web Development with Rails, 2nd Ed." # We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information. #--- class Cart include Amrita2::DictionaryData attr_reader :items def initialize @items = [] end def add_product(product) current_item = @items.find {|item| item.product == product} if current_item current_item.increment_quantity else current_item = CartItem.new(product) @items << current_item end current_item end def total_items @items.sum { |item| item.quantity } end def total_price @items.sum { |item| item.price } end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
amrita2-2.0.0 | sample/depot/app/models/cart.rb |
amrita2-2.0.1 | sample/depot/app/models/cart.rb |
amrita2-2.0.2 | sample/depot/app/models/cart.rb |