Class: NetworkExecutive::ProgramSchedule

Inherits:
Object
  • Object
show all
Defined in:
lib/network_executive/program_schedule.rb

Direct Known Subclasses

OffAirSchedule

Defined Under Namespace

Classes: Occurrence

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program, options = {}, &block) ⇒ ProgramSchedule

Returns a new instance of ProgramSchedule.

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/network_executive/program_schedule.rb', line 9

def initialize( program, options = {}, &block )
  options.symbolize_keys!

  options[:duration] ||= 24.hours

  @start_time, @duration = options[:start_time], options[:duration]

  @program = Program.find_by_name program

  raise ProgramNameError, %Q{"#{program}" is not a registered Program} unless @program

  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/network_executive/program_schedule.rb', line 77

def method_missing( method_id, *args )
  if program.respond_to?( method_id )
    program.send method_id, *args
  elsif proxy.respond_to?( method_id )
    proxy.send method_id, *args
  else
    super
  end
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



5
6
7
# File 'lib/network_executive/program_schedule.rb', line 5

def duration
  @duration
end

#programObject

Returns the value of attribute program.



5
6
7
# File 'lib/network_executive/program_schedule.rb', line 5

def program
  @program
end

#proxyObject

Returns the value of attribute proxy.



5
6
7
# File 'lib/network_executive/program_schedule.rb', line 5

def proxy
  @proxy
end

#start_timeObject

Returns the value of attribute start_time.



5
6
7
# File 'lib/network_executive/program_schedule.rb', line 5

def start_time
  @start_time
end

Instance Method Details

#occurrence_at(time) ⇒ Object

Returns the scheduled occurrence that matches the specified time



60
61
62
63
64
65
66
67
68
69
# File 'lib/network_executive/program_schedule.rb', line 60

def occurrence_at( time )
  real_duration = duration - 1

  range = [ time - real_duration, time ]

  start_time = proxy.occurrences_between( range[0], range[1] ).first
  end_time   = start_time + real_duration

  Occurrence.new start_time, real_duration, end_time
end

#occurs_at?(time) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/network_executive/program_schedule.rb', line 47

def occurs_at?( time )
  proxy.occurs_at? time
end

#play(&block) ⇒ Object



51
52
53
# File 'lib/network_executive/program_schedule.rb', line 51

def play( &block )
  program.play( &block )
end

#respond_to_missing?(method_id, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/network_executive/program_schedule.rb', line 71

def respond_to_missing?( method_id, include_private = false )
  proxy.respond_to?( method_id ) \
    || program.respond_to?( method_id ) \
    || super
end

#update(&block) ⇒ Object



55
56
57
# File 'lib/network_executive/program_schedule.rb', line 55

def update( &block )
  program.update( &block )
end

#whats_on?(time = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/network_executive/program_schedule.rb', line 43

def whats_on?( time = Time.now )
  proxy.occurring_at? time
end