1 class Customer < ActiveRecord::Base
3 has_many :merchandise_purchases
4 has_many :rentable_purchases
6 validates_presence_of :name, :email, :phone, :address
7 validates_numericality_of :debt
10 coitems = Coitem.find_all_by_customer_id(id)
14 if item.rentable.class == Video
23 coitems = Coitem.find_all_by_customer_id(id)
27 if item.rentable.class == Game
36 coitems = Coitem.find_all_by_customer_id(id)
37 overdue_video_count = 0
40 if item.rentable.class == Video and item.overdue?
41 overdue_video_count += 1
45 return overdue_video_count
49 coitems = Coitem.find_all_by_customer_id(id)
50 overdue_game_count = 0
53 if item.rentable.class == Game and item.overdue?
54 overdue_game_count += 1
58 return overdue_game_count
64 errors.add(:debt, "should be non-negative") if debt.nil? || debt < 0.00
65 errors.add(:email, "is invalid") unless email =~ /.+@.+\..+/
66 errors.add(:phone, "has invalid format, use XXX-XXX-XXXX") unless phone =~ /^\d{3}-\d{3}-\d{4}$/