Class: TVTid::Schedule
- Inherits:
-
Object
- Object
- TVTid::Schedule
- Defined in:
- library/tvtid/schedule.rb
Instance Attribute Summary collapse
-
#channel ⇒ Channel
readonly
The channel the schedule belongs to.
-
#programs ⇒ Array<Program>
readonly
The list of programs in the schedule.
Instance Method Summary collapse
-
#at(time) ⇒ (Array<Program>, Program, Array<Program>)
Returns the previous, current and upcoming programs at a given ‘time`.
-
#current ⇒ (Array<Program>, Program, Array<Program>)
The previous, the current and the upcoming programs relative to the current time.
-
#initialize(channel, programs = []) ⇒ Schedule
constructor
Constructs a new schedule for a channel.
Constructor Details
#initialize(channel, programs = []) ⇒ Schedule
Constructs a new schedule for a channel.
12 13 14 15 |
# File 'library/tvtid/schedule.rb', line 12 def initialize channel, programs = [] @channel = channel @programs = programs end |
Instance Attribute Details
#channel ⇒ Channel (readonly)
Returns the channel the schedule belongs to.
4 5 6 |
# File 'library/tvtid/schedule.rb', line 4 def channel @channel end |
#programs ⇒ Array<Program> (readonly)
Returns the list of programs in the schedule.
6 7 8 |
# File 'library/tvtid/schedule.rb', line 6 def programs @programs end |
Instance Method Details
#at(time) ⇒ (Array<Program>, Program, Array<Program>)
Returns the previous, current and upcoming programs at a given ‘time`.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 |