Class: Sequencer::Loop

Inherits:
Object
  • Object
show all
Defined in:
lib/sequencer/loop.rb

Overview

Define a looping behavior for the sequencer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoop

Returns a new instance of Loop


8
9
10
11
12
# File 'lib/sequencer/loop.rb', line 8

def initialize
  @count = 0
  @range = nil
  @is_disabled = false
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count


6
7
8
# File 'lib/sequencer/loop.rb', line 6

def count
  @count
end

#rangeObject

Returns the value of attribute range


6
7
8
# File 'lib/sequencer/loop.rb', line 6

def range
  @range
end

Instance Method Details

#default?Boolean

Is this a default loop? The default loops around the start and end of the sequence

Returns:

  • (Boolean)

36
37
38
# File 'lib/sequencer/loop.rb', line 36

def default?
  @range.nil?
end

#disableBoolean

Disable looping

Returns:

  • (Boolean)

48
49
50
# File 'lib/sequencer/loop.rb', line 48

def disable
  @is_disabled = true
end

#disabled?Boolean

Is looping disabled?

Returns:

  • (Boolean)

42
43
44
# File 'lib/sequencer/loop.rb', line 42

def disabled?
  @is_disabled
end

#in_bounds?(pointer, options = {}) ⇒ Boolean

Is the given pointer position in bounds of the loop?

Parameters:

  • pointer (Fixnum)

    The pointer position to compare bounds to

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :length (Fixnum)

    The sequence length (required if default loop is being used)

Returns:

  • (Boolean)

57
58
59
60
61
# 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

#nextFixnum

Mark a completed loop and return the start position

Returns:

  • (Fixnum)

    The loop start position (see Loop#start)


29
30
31
32
# File 'lib/sequencer/loop.rb', line 29

def next
  @count += 1
  start
end

#startFixnum

The starting pointer position for this loop. For the default loop, position is 0

Returns:

  • (Fixnum)

23
24
25
# File 'lib/sequencer/loop.rb', line 23

def start
  default? ? 0 : @range.begin
end