Skip to content

Instantly share code, notes, and snippets.

@h-lame
Created October 5, 2009 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-lame/202246 to your computer and use it in GitHub Desktop.
Save h-lame/202246 to your computer and use it in GitHub Desktop.
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