class TVTid::Schedule

Attributes

channel[R]

@return [Channel] the channel the schedule belongs to.

programs[R]

@return [Array<Program>] the list of programs in the schedule.

Public Class Methods

new(channel, programs = []) click to toggle source

Constructs a new schedule for a channel.

@param channel [Channel] the parent channel @param programs [Array<Program>] a list of programs

# File library/tvtid/schedule.rb, line 12
def initialize channel, programs = []
  @channel = channel
  @programs = programs
end

Public Instance Methods

at(time) click to toggle source

Returns the previous, current and upcoming programs at a given `time`.

@return [(Array<Program>, Program, Array<Program>)] the previous, the

current and the upcoming programs relative to the given `time`.
# File library/tvtid/schedule.rb, line 21
def at time
  cur_idx = 0

  @programs.each_with_index do |program, index|
    if program.start_time <= time and program.stop_time >= time
      cur_idx = index
      break
    end
  end

  if cur_idx != 0
    return @programs[0..cur_idx-1], @programs[cur_idx], @programs[cur_idx+1..-1]
  end
end
current() click to toggle source

@return [(Array<Program>, Program, Array<Program>)] the previous, the

current and the upcoming programs relative to the current time.
# File library/tvtid/schedule.rb, line 38
def current
  self.at DateTime.now
end