Add MaxVideos and MaxGames RentablePolicies
[cs356-p2-videostore.git] / app / models / customer.rb
index aba5044..e56eafe 100644 (file)
@@ -7,6 +7,32 @@ class Customer < ActiveRecord::Base
   validates_presence_of :name, :email, :phone, :address
   validates_numericality_of :debt
 
+  def checked_out_videos
+    coitems = Coitem.find_all_by_customer_id(id)
+    video_count = 0
+
+    for item in coitems
+      if item.rentable.class == Video
+        video_count += 1
+      end
+    end
+
+    return video_count
+  end
+
+  def checked_out_games
+    coitems = Coitem.find_all_by_customer_id(id)
+    game_count = 0
+
+    for item in coitems
+      if item.rentable.class == Game
+        game_count += 1
+      end
+    end
+
+    return game_count
+  end
+
   protected
 
   def validate