Class: Wakame::Scheduler::LoopSequence
- Defined in:
- lib/wakame/scheduler.rb
Instance Method Summary collapse
-
#initialize(timed_seq) ⇒ LoopSequence
constructor
A new instance of LoopSequence.
- #next_event(time) ⇒ Object
- #value_at(time) ⇒ Object
Constructor Details
#initialize(timed_seq) ⇒ LoopSequence
Returns a new instance of LoopSequence.
35 36 37 38 |
# File 'lib/wakame/scheduler.rb', line 35 def initialize(timed_seq) raise ArgumentError unless timed_seq.is_a?(TimedSequence) @timed_sequence = timed_seq end |
Instance Method Details
#next_event(time) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wakame/scheduler.rb', line 41 def next_event(time) @timed_sequence.start_at ||= time unless @timed_sequence.range_check?(time) @timed_sequence.start_at = time end event = @timed_sequence.next_event(time) if event.nil? puts "overwrap : #{time}" # Here comes means that the current offset time is larger than the last offset time. # So the value at next first offset time will become the return value. f = @timed_sequence.first_event #l = @timed_sequence.last_event offset = ((@timed_sequence.start_at + @timed_sequence.duration) - time) + f[0] event = [offset, f[1]] end event end |
#value_at(time) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/wakame/scheduler.rb', line 62 def value_at(time) @timed_sequence.start_at ||= time unless @timed_sequence.range_check?(time) @timed_sequence.start_at = time end #next_event(time) @timed_sequence.value_at(time) end |