1 class Customer < ActiveRecord::Base
4 has_many :merchandise_purchases
5 has_many :rentable_purchases
7 validates_presence_of :name, :email, :phone, :address
8 validates_numericality_of :debt
10 def checked_out_videos
11 coitems = Coitem.find_all_by_customer_id(id)
15 if item.rentable.class == Video
24 coitems = Coitem.find_all_by_customer_id(id)
28 if item.rentable.class == Game
37 coitems = Coitem.find_all_by_customer_id(id)
38 overdue_video_count = 0
41 if item.rentable.class == Video and item.overdue?
42 overdue_video_count += 1
46 return overdue_video_count
50 coitems = Coitem.find_all_by_customer_id(id)
51 overdue_game_count = 0
54 if item.rentable.class == Game and item.overdue?
55 overdue_game_count += 1
59 return overdue_game_count
65 errors.add(:debt, "should be non-negative") if debt.nil? || debt < 0.00