X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=app%2Fmodels%2Fgame.rb;h=a2d324a5f74f3e5156e9d6e46756d59a1ba8badf;hb=50e2ce05003eb4a56d1daa8e030a2f477aeb59bc;hp=4991aa91a52d568235ab94b8f0dc0da6d7f854a8;hpb=3650c5f411112965a12718b75ccbedde3186fa15;p=cs356-p2-videostore.git diff --git a/app/models/game.rb b/app/models/game.rb index 4991aa9..a2d324a 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,4 +1,44 @@ class Game < Rentable - validates_presence_of :game_genre - validates_presence_of :platform + has_many :game_genres + has_many :game_platforms + + validates_presence_of :game_genre_id + validates_presence_of :game_platform_id + + def genre + GameGenre.find_by_id(game_genre_id) + end + + def platform + GamePlatform.find_by_id(game_platform_id) + end + + def calculated_price + # FIXME: generate this based on day of week, newrelease + day_of_week = Time.now.to_date.wday + base_fee = GamePolicy.find_by_day(day_of_week).fee + + # Check for newrelease + newrelease_fee = newrelease ? GamePolicy.find_by_day(8).fee : 0.00 + + return base_fee + newrelease_fee + end + + def due_date + # FIXME: generate this based on the day of week, newrelease + # NOTE: a Date.wday will tell you the day of week (0-6, meaning Sunday-Saturday) + day_of_week = Time.now.to_date.wday + base_period = GamePolicy.find_by_day(day_of_week).period + newrelease_period = newrelease ? GamePolicy.find_by_day(8).period : 0 + + period = base_period + newrelease_period + return Time.now.advance(:days => period).to_date + end + + protected + def validate + errors.add(:game_genre_id, "does not exist in the database") if genre.nil? + errors.add(:game_platform_id, "does not exist in the database") if platform.nil? + end + end