class Sequencer::Loop

Define a looping behavior for the sequencer

Attributes

count[R]
range[R]

Public Class Methods

new() click to toggle source
# File lib/sequencer/loop.rb, line 8
def initialize
  @count = 0
  @range = nil
  @is_disabled = false
end

Public Instance Methods

default?() click to toggle source

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() click to toggle source

Disable looping @return [Boolean]

# File lib/sequencer/loop.rb, line 48
def disable
  @is_disabled = true
end
disabled?() click to toggle source

Is looping disabled? @return [Boolean]

# File lib/sequencer/loop.rb, line 42
def disabled?
  @is_disabled
end
in_bounds?(pointer, options = {}) click to toggle source

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
next() click to toggle source

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
range=(value) click to toggle source

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
start() click to toggle source

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

to_range(value) click to toggle source

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