class Sequencer::Loop
Define a looping behavior for the sequencer
Attributes
Public Class Methods
# File lib/sequencer/loop.rb, line 8 def initialize @count = 0 @range = nil @is_disabled = false end
Public Instance Methods
Is this a default loop? The default loops around the start and end of the sequence @return [Boolean]
# File lib/sequencer/loop.rb, line 36 def default? @range.nil? end
Disable looping @return [Boolean]
# File lib/sequencer/loop.rb, line 48 def disable @is_disabled = true end
Is looping disabled? @return [Boolean]
# File lib/sequencer/loop.rb, line 42 def disabled? @is_disabled end
Is the given pointer position in bounds of the loop? @param [Fixnum] pointer The pointer position to compare bounds to @param [Hash] options @option options [Fixnum] :length The sequence length (required if default loop is being used) @return [Boolean]
# File lib/sequencer/loop.rb, line 57 def in_bounds?(pointer, options = {}) length = options[:length] range = default? ? 0..(length-1) : @range range.include?(pointer) end
Mark a completed loop and return the start position @return [Fixnum] The loop start position (see Loop#start
)
# File lib/sequencer/loop.rb, line 29 def next @count += 1 start end
Set the loop range @param [Array<Fixnum>, FalseClass, Fixnum, Range] value @return [FalseClass, Range]
# File lib/sequencer/loop.rb, line 17 def range=(value) @range = to_range(value) end
The starting pointer position for this loop. For the default loop, position is 0 @return [Fixnum]
# File lib/sequencer/loop.rb, line 23 def start default? ? 0 : @range.begin end
Private Instance Methods
Convert the given value to a range @param [Array<Fixnum>, Fixnum, Range] value @return [FalseClass, Range]
# File lib/sequencer/loop.rb, line 68 def to_range(value) case value when Array then (value[0]..value[1]) when Fixnum then (0..value) when Range then value end end