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
- #increment(delays:, inputs:, duration: nil) ⇒ Object
-
#initialize ⇒ Cursor
constructor
A new instance of Cursor.
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
#increment(delays:, inputs:, duration: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/matrix/cursor.rb', line 13 def increment(delays:, inputs:, duration: nil) next_index = @index + 1 duration = now - @last_update if duration.nil? if delays[next_index] && duration >= delays[next_index] @index += 1 @index = 0 if index >= inputs.count @last_update = now yield index end end |