class Canis::Circular
a structure that maintains position and gives next and previous taking max index into account. it also circles. Can be used for traversing next component in a form, or container, or columns in a table.
Attributes
current_index[R]
last_index[R]
Public Class Methods
new(m, c=0)
click to toggle source
# File lib/canis/core/widgets/table.rb, line 53 def initialize m, c=0 raise "max index cannot be nil" unless m @max_index = m @current_index = c @last_index = c end
Public Instance Methods
is_last?()
click to toggle source
# File lib/canis/core/widgets/table.rb, line 75 def is_last? @current_index == @max_index end
next()
click to toggle source
# File lib/canis/core/widgets/table.rb, line 59 def next @last_index = @current_index if @current_index + 1 > @max_index @current_index = 0 else @current_index += 1 end end
previous()
click to toggle source
# File lib/canis/core/widgets/table.rb, line 67 def previous @last_index = @current_index if @current_index - 1 < 0 @current_index = @max_index else @current_index -= 1 end end