Class: Rain::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/matrix/cursor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCursor

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_updateObject

Returns the value of attribute first_update.



5
6
7
# File 'lib/matrix/cursor.rb', line 5

def first_update
  @first_update
end

#indexObject

Returns the value of attribute index.



5
6
7
# File 'lib/matrix/cursor.rb', line 5

def index
  @index
end

#last_updateObject

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