Class: Sequencer::Loop
- Inherits:
-
Object
- Object
- Sequencer::Loop
- Defined in:
- lib/sequencer/loop.rb
Overview
Define a looping behavior for the sequencer
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#range ⇒ Object
Returns the value of attribute range.
Instance Method Summary collapse
-
#default? ⇒ Boolean
Is this a default loop? The default loops around the start and end of the sequence.
-
#disable ⇒ Boolean
Disable looping.
-
#disabled? ⇒ Boolean
Is looping disabled?.
-
#in_bounds?(pointer, options = {}) ⇒ Boolean
Is the given pointer position in bounds of the loop?.
-
#initialize ⇒ Loop
constructor
A new instance of Loop.
-
#next ⇒ Fixnum
Mark a completed loop and return the start position.
-
#start ⇒ Fixnum
The starting pointer position for this loop.
Constructor Details
#initialize ⇒ Loop
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
#count ⇒ Object (readonly)
Returns the value of attribute count.
6 7 8 |
# File 'lib/sequencer/loop.rb', line 6 def count @count end |
#range ⇒ Object
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
36 37 38 |
# File 'lib/sequencer/loop.rb', line 36 def default? @range.nil? end |
#disable ⇒ Boolean
Disable looping
48 49 50 |
# File 'lib/sequencer/loop.rb', line 48 def disable @is_disabled = true end |
#disabled? ⇒ Boolean
Is looping disabled?
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?
57 58 59 60 61 |
# File 'lib/sequencer/loop.rb', line 57 def in_bounds?(pointer, = {}) length = [:length] range = default? ? 0..(length-1) : @range range.include?(pointer) end |
#next ⇒ Fixnum
Mark a completed loop and return the start position
29 30 31 32 |
# File 'lib/sequencer/loop.rb', line 29 def next @count += 1 start end |
#start ⇒ Fixnum
The starting pointer position for this loop. For the default loop, position is 0
23 24 25 |
# File 'lib/sequencer/loop.rb', line 23 def start default? ? 0 : @range.begin end |