Add the Gameplatform MVC to handle the different game platforms
[cs356-p2-videostore.git] / app / models / game.rb
1 class Game < Rentable
2   validates_presence_of :game_genre
3   validates_presence_of :platform
4
5   def genre
6     return Gamegenre.find(game_genre).name
7   end
8
9   def game_platform
10     return Gameplatform.find(platform).name
11   end
12
13   def calculated_price
14     # FIXME: generate this based on day of week, newrelease
15     day_of_week = Time.now.to_date.wday
16     base_fee = GamePolicy.find_by_day(day_of_week).fee
17
18     # Check for newrelease
19     newrelease_fee = newrelease ? GamePolicy.find_by_day(8).fee : 0.00
20
21     return base_fee + newrelease_fee
22   end
23
24   def due_date
25     # FIXME: generate this based on the day of week, newrelease
26     # NOTE: a Date.wday will tell you the day of week (0-6, meaning Sunday-Saturday)
27     day_of_week = Time.now.to_date.wday
28     base_period = GamePolicy.find_by_day(day_of_week).period
29     newrelease_period = newrelease ? GamePolicy.find_by_day(8).period : 0
30
31     period = base_period + newrelease_period
32     return Time.now.advance(:days => period).to_date
33   end
34
35 end