Lots of stuff, I got too tired to keep perfect revision history
[cs356-p2-videostore.git] / app / models / bonus_policy.rb
1 class BonusPolicy < ActiveRecord::Base
2
3   validates_presence_of :number
4   validates_presence_of :bonus_type
5   validates_presence_of :days
6
7   validates_numericality_of :number
8   validates_numericality_of :days
9
10   def description
11     return "One #{bonus_type} free after #{number} #{bonus_type} rentals in the last #{days} days"
12   end
13
14   protected
15   def validate
16     errors.add(:days, "must be at least 1") if days.nil? || days < 1
17     errors.add(:number, "must be at least 1") if number.nil? || number < 1
18     errors.add(:bonus_type, "must be either Video or Game") unless bonus_type == 'Video' or bonus_type == 'Game'
19   end
20 end