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
7 validates_numericality_of :day
8 validates_numericality_of :fee
9 validates_numericality_of :period
11 # Find the base fee for today
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
18 # Find the base rental period for today
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
25 # Find the fee for overdue videos (per day)
28 return VideoPolicy.find_by_day(overdue_day).fee
33 errors.add(:fee, "must be greater than $0.01") if fee < 0.01