Class: Sequencer::Event
- Inherits:
-
Object
- Object
- Sequencer::Event
- Defined in:
- lib/sequencer/event.rb
Overview
Events that are fired by the sequencer
Instance Method Summary collapse
- #do_next(pointer, data) ⇒ Array<Object>
-
#do_perform(data) ⇒ Boolean
Fire the perform event.
-
#do_step ⇒ Boolean
Fire the step events.
-
#do_stop ⇒ Boolean
Fire the stop event.
-
#initialize ⇒ Event
constructor
A new instance of Event.
-
#next(pointer = nil, &block) ⇒ Array<Proc>
Fire an event the next time the pointer reaches the given number.
-
#next?(pointer = nil) ⇒ Boolean
Whether any callbacks exist for the given pointer (or nil).
-
#perform(&block) ⇒ Proc
Set the perform event.
-
#step(&block) ⇒ Proc
Set the step event.
-
#stop(&block) ⇒ Proc
Access the stop events.
Constructor Details
#initialize ⇒ Event
Returns a new instance of Event.
6 7 8 9 10 11 |
# File 'lib/sequencer/event.rb', line 6 def initialize @next = {} @perform = [] @step = [] @stop = [] end |
Instance Method Details
#do_next(pointer, data) ⇒ Array<Object>
36 37 38 39 40 |
# File 'lib/sequencer/event.rb', line 36 def do_next(pointer, data) keys = [pointer, nil] callbacks = keys.map { |key| @next.delete(key) }.flatten.compact callbacks.map(&:call) end |
#do_perform(data) ⇒ Boolean
Fire the perform event
90 91 92 |
# File 'lib/sequencer/event.rb', line 90 def do_perform(data) @perform.map { |callback| callback.call(data) } end |
#do_step ⇒ Boolean
Fire the step events
55 56 57 |
# File 'lib/sequencer/event.rb', line 55 def do_step @step.map(&:call) end |
#do_stop ⇒ Boolean
Fire the stop event
72 73 74 |
# File 'lib/sequencer/event.rb', line 72 def do_stop @stop.map(&:call) end |
#next(pointer = nil, &block) ⇒ Array<Proc>
Fire an event the next time the pointer reaches the given number
17 18 19 20 21 22 23 24 |
# File 'lib/sequencer/event.rb', line 17 def next(pointer = nil, &block) @next[pointer] ||= [] if block_given? @next[pointer].clear @next[pointer] << block end @next[pointer] end |
#next?(pointer = nil) ⇒ Boolean
Whether any callbacks exist for the given pointer (or nil)
29 30 31 |
# File 'lib/sequencer/event.rb', line 29 def next?(pointer = nil) !@next[pointer].nil? end |
#perform(&block) ⇒ Proc
Set the perform event
79 80 81 82 83 84 85 |
# File 'lib/sequencer/event.rb', line 79 def perform(&block) if block_given? @perform.clear @perform << block end @perform end |
#step(&block) ⇒ Proc
Set the step event
45 46 47 48 49 50 51 |
# File 'lib/sequencer/event.rb', line 45 def step(&block) if block_given? @step.clear @step << block end @step end |
#stop(&block) ⇒ Proc
Access the stop events
62 63 64 65 66 67 68 |
# File 'lib/sequencer/event.rb', line 62 def stop(&block) if block_given? @stop.clear @stop << block end @stop end |