Class: NetworkExecutive::ProgramSchedule
- Inherits:
-
Object
- Object
- NetworkExecutive::ProgramSchedule
- Defined in:
- lib/network_executive/program_schedule.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Occurrence
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#program ⇒ Object
Returns the value of attribute program.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#initialize(program, options = {}, &block) ⇒ ProgramSchedule
constructor
A new instance of ProgramSchedule.
- #method_missing(method_id, *args) ⇒ Object
-
#occurrence_at(time) ⇒ Object
Returns the scheduled occurrence that matches the specified time.
- #occurs_at?(time) ⇒ Boolean
- #play(&block) ⇒ Object
- #respond_to_missing?(method_id, include_private = false) ⇒ Boolean
- #update(&block) ⇒ Object
- #whats_on?(time = Time.now) ⇒ Boolean
Constructor Details
#initialize(program, options = {}, &block) ⇒ ProgramSchedule
Returns a new instance of ProgramSchedule.
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, = {}, &block ) .symbolize_keys! [:duration] ||= 24.hours @start_time, @duration = [:start_time], [: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
#duration ⇒ Object
Returns the value of attribute duration.
5 6 7 |
# File 'lib/network_executive/program_schedule.rb', line 5 def duration @duration end |
#program ⇒ Object
Returns the value of attribute program.
5 6 7 |
# File 'lib/network_executive/program_schedule.rb', line 5 def program @program end |
#proxy ⇒ Object
Returns the value of attribute proxy.
5 6 7 |
# File 'lib/network_executive/program_schedule.rb', line 5 def proxy @proxy end |
#start_time ⇒ Object
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
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
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
43 44 45 |
# File 'lib/network_executive/program_schedule.rb', line 43 def whats_on?( time = Time.now ) proxy.occurring_at? time end |