Created
October 5, 2009 17:04
-
-
Save h-lame/202246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Schedule | |
def initialize(service) | |
@service = service | |
end | |
attr_accessor :schedule | |
def day | |
(1..23).map { [] } | |
end | |
def week | |
(1..7).map { day } | |
end | |
def today | |
todays_broadcasts = @service.broadcasts.today | |
@schedule = Day.fill(self.day, todays_broadcasts) | |
end | |
module Day | |
def self.fill(schedule, broadcasts) | |
broadcasts.each do |broadcast| | |
first_timeslot = (broadcast.start_time < Date.today.midnight) ? 0 : broadcast.start_time.hour | |
last_timeslot = (broadcast.end_time > Date.tomorrow.midnight) ? 23 : broadcast.end_time.hour | |
last_timeslot -= 1 if (broadcast.end_time.min == 0 && broadcast.end_time.sec == 0) | |
(first_timeslot..last_timeslot).each do |slot| | |
schedule[slot] << broadcast | |
end | |
end | |
schedule | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment