Class: RubyCurses::Circular
- Inherits:
-
Struct
- Object
- Struct
- RubyCurses::Circular
- Defined in:
- lib/rbcurse/experimental/widgets/tablewidget.rb
Overview
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.
Instance Attribute Summary collapse
-
#current_index ⇒ Object
Returns the value of attribute current_index.
-
#last_index ⇒ Object
readonly
Returns the value of attribute last_index.
-
#max_index ⇒ Object
Returns the value of attribute max_index.
Instance Method Summary collapse
-
#initialize(m, c = 0) ⇒ Circular
constructor
A new instance of Circular.
- #is_last? ⇒ Boolean
- #next ⇒ Object
- #previous ⇒ Object
Constructor Details
#initialize(m, c = 0) ⇒ Circular
Returns a new instance of Circular.
43 44 45 46 47 48 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 43 def initialize m, c=0 raise "max index cannot be nil" unless m @max_index = m @current_index = c @last_index = c end |
Instance Attribute Details
#current_index ⇒ Object
Returns the value of attribute current_index
40 41 42 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 40 def current_index @current_index end |
#last_index ⇒ Object (readonly)
Returns the value of attribute last_index.
41 42 43 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 41 def last_index @last_index end |
#max_index ⇒ Object
Returns the value of attribute max_index
40 41 42 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 40 def max_index @max_index end |
Instance Method Details
#is_last? ⇒ Boolean
65 66 67 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 65 def is_last? @current_index == @max_index end |
#next ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 49 def next @last_index = @current_index if @current_index + 1 > @max_index @current_index = 0 else @current_index += 1 end end |
#previous ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 57 def previous @last_index = @current_index if @current_index - 1 < 0 @current_index = @max_index else @current_index -= 1 end end |