Class: Rain::Cursor
- Inherits:
-
Object
- Object
- Rain::Cursor
- Defined in:
- lib/matrix/cursor.rb
Instance Attribute Summary collapse
-
#first_update ⇒ Object
Returns the value of attribute first_update.
-
#index ⇒ Object
Returns the value of attribute index.
-
#last_update ⇒ Object
Returns the value of attribute last_update.
Instance Method Summary collapse
- #increase_index(loop_count:) ⇒ Object
-
#increment(delays:, inputs:, duration: nil) {|index| ... } ⇒ Object
Unit tests use “duration” to skip forward in time, while feature tests and the real world use old fashioned linear time.
-
#initialize ⇒ Cursor
constructor
A new instance of Cursor.
- #iterate(inputs:, loop_count:) ⇒ Object
- #next_index(loop_count:) ⇒ Object
Constructor Details
#initialize ⇒ Cursor
Returns a new instance of Cursor.
7 8 9 10 11 |
# File 'lib/matrix/cursor.rb', line 7 def initialize @index = -1 @first_update = now @last_update = now end |
Instance Attribute Details
#first_update ⇒ Object
Returns the value of attribute first_update.
5 6 7 |
# File 'lib/matrix/cursor.rb', line 5 def first_update @first_update end |
#index ⇒ Object
Returns the value of attribute index.
5 6 7 |
# File 'lib/matrix/cursor.rb', line 5 def index @index end |
#last_update ⇒ Object
Returns the value of attribute last_update.
5 6 7 |
# File 'lib/matrix/cursor.rb', line 5 def last_update @last_update end |
Instance Method Details
#increase_index(loop_count:) ⇒ Object
34 35 36 37 |
# File 'lib/matrix/cursor.rb', line 34 def increase_index(loop_count:) @index += 1 @index = 0 if @index >= loop_count end |
#increment(delays:, inputs:, duration: nil) {|index| ... } ⇒ Object
Unit tests use “duration” to skip forward in time, while feature tests and the real world use old fashioned linear time.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/matrix/cursor.rb', line 14 def increment(delays:, inputs:, duration: nil) next_index = next_index(loop_count: inputs.count) return unless delays[next_index] && (duration || now - @last_update) >= delays[next_index] @index = next_index @last_update = now yield index end |
#iterate(inputs:, loop_count:) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/matrix/cursor.rb', line 25 def iterate(inputs:, loop_count:) inputs.each do |input| @index += 1 @index = 0 if index >= loop_count yield index, input end end |
#next_index(loop_count:) ⇒ Object
39 40 41 42 43 |
# File 'lib/matrix/cursor.rb', line 39 def next_index(loop_count:) next_index = @index + 1 next_index = 0 if next_index >= loop_count next_index end |