X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=app%2Fmodels%2Fgame.rb;h=a2d324a5f74f3e5156e9d6e46756d59a1ba8badf;hb=50e2ce05003eb4a56d1daa8e030a2f477aeb59bc;hp=4c5d38c2142d8003b54d9398536d6ce08c1623ca;hpb=0dccca2d3c0e9d5e6eaa1c1ebee3670654fd8c43;p=cs356-p2-videostore.git diff --git a/app/models/game.rb b/app/models/game.rb index 4c5d38c..a2d324a 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,8 +1,44 @@ class Game < Rentable - validates_presence_of :game_genre - validates_presence_of :platform + has_many :game_genres + has_many :game_platforms - def checkedout? - return Coitem.find_by_id(self.id) ? true : false + 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