X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=app%2Fmodels%2Fvideo.rb;h=8ca39012a4d62a61edecfb5b7d8c2c8f9d0a862c;hb=da871e3e27c31759e0d017c89ccf16a14db1a227;hp=6f75a265c45299a66e30696ba50cf21ac8c9d652;hpb=56db4e1da35c068e247eadbd32edd0a09eb61127;p=cs356-p2-videostore.git diff --git a/app/models/video.rb b/app/models/video.rb index 6f75a26..8ca3901 100644 --- a/app/models/video.rb +++ b/app/models/video.rb @@ -1,24 +1,42 @@ class Video < Rentable has_many :video_genres - has_many :medias + has_many :video_medias validates_presence_of :director - validates_presence_of :video_genre - validates_presence_of :media + validates_presence_of :video_genre_id + validates_presence_of :video_media_id + + def genre + VideoGenre.find_by_id(video_genre_id) + end + + def media + VideoMedia.find_by_id(video_media_id) + end def calculated_price - # FIXME: generate this based on day of week, newrelase - return 11 + day_of_week = Time.now.to_date.wday + base_fee = VideoPolicy.find_by_day(day_of_week).fee + + # Check for newrelease + newrelease_fee = newrelease ? VideoPolicy.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 - return Time.now.advance(:days => 2).to_date + # 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 = VideoPolicy.find_by_day(day_of_week).period + newrelease_period = newrelease ? VideoPolicy.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(:video_genre, "does not exist in the database") if video_genre.nil? - errors.add(:media, "does not exist in the database") if media.nil? + errors.add(:video_genre_id, "does not exist in the database") if genre.nil? + errors.add(:video_media_id, "does not exist in the database") if media.nil? end end