Guest User

Untitled

a guest
Feb 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class CartItem
  2. include Reloadable
  3.  
  4. attr_reader :serving, :quantity
  5.  
  6. def initialize(serving)
  7. @serving = serving
  8. @quantity = 1
  9. end
  10.  
  11. def increment_quantity
  12. @quantity += 1
  13. end
  14.  
  15. def name
  16. @serving.item.name
  17. end
  18.  
  19. def size
  20. @serving.size.name
  21. end
  22.  
  23. def price
  24. @serving.price * @quantity
  25. end
  26.  
  27. def total_price
  28. @items.inject(0) { |sum, line_item| sum + line_item.price }
  29. end
  30.  
  31. end
Add Comment
Please, Sign In to add comment