Add the VideoPolicy model, to hold all the base prices and periods
[cs356-p2-videostore.git] / app / models / video_policy.rb
1 class VideoPolicy < ActiveRecord::Base
2   validates_presence_of :day
3   validates_presence_of :fee
4   validates_presence_of :period
5   validates_presence_of :description
6
7   validates_numericality_of :day
8   validates_numericality_of :fee
9   validates_numericality_of :period
10
11   # Find the base fee for today
12   def todays_fee
13     # Gets the current day of the week in 0-6 == Sun-Sat form
14     day_of_week = Time.now.to_date.wday
15     return VideoPolicy.find_by_day(day_of_week).fee
16   end
17
18   # Find the base rental period for today
19   def todays_period
20     # Gets the current day of the week in 0-6 == Sun-Sat form
21     day_of_week = Time.now.to_date.wday
22     return VideoPolicy.find_by_day(day_of_week).period
23   end
24
25   # Find the fee for overdue videos (per day)
26   def overdue_fee
27     overdue_day = 7
28     return VideoPolicy.find_by_day(overdue_day).fee
29   end
30
31   protected
32   def validate
33     errors.add(:fee, "must be greater than $0.01") if fee < 0.01
34   end
35 end