class Sequencer::Event
Events that are fired by the sequencer
Public Class Methods
# File lib/sequencer/event.rb, line 6 def initialize @next = {} @perform = [] @step = [] @stop = [] end
Public Instance Methods
@param [Fixnum, nil] pointer The pointer number (or nil) to fire callbacks for. @param [Object] data The data for the current pointer @return [Array<Object>]
# 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
Fire the perform event @param [Object] data Data for the current sequence step @return [Boolean]
# File lib/sequencer/event.rb, line 90 def do_perform(data) @perform.map { |callback| callback.call(data) } end
Fire the step events @return [Boolean]
# File lib/sequencer/event.rb, line 55 def do_step @step.map(&:call) end
Fire the stop event @return [Boolean]
# File lib/sequencer/event.rb, line 72 def do_stop @stop.map(&:call) end
Fire an event the next time the pointer reaches the given number @param [Fixnum, nil] pointer The pointer number when the callback should be fired. If nil, it will be fired whenever Event#do_next
is called. @param [Proc] block @return [Array<Proc>]
# 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
Whether any callbacks exist for the given pointer (or nil) @param [Fixnum, nil] pointer @return [Boolean]
# File lib/sequencer/event.rb, line 29 def next?(pointer = nil) !@next[pointer].nil? end
Set the perform event @param [Proc] block @return [Proc]
# File lib/sequencer/event.rb, line 79 def perform(&block) if block_given? @perform.clear @perform << block end @perform end
Set the step event @param [Proc] block @return [Proc]
# File lib/sequencer/event.rb, line 45 def step(&block) if block_given? @step.clear @step << block end @step end
Access the stop events @param [Proc] block @return [Proc]
# File lib/sequencer/event.rb, line 62 def stop(&block) if block_given? @stop.clear @stop << block end @stop end