Class: RubyCurses::History
- Defined in:
- lib/rbcurse/core/util/bottomline.rb
Overview
just so the program does not bomb due to a tiny feature I do not raise error on nil array, i create a dummy array which you likely will not be able to use, in any case it will have only one value
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#current_index ⇒ Object
Returns the value of attribute current_index.
-
#last_index ⇒ Object
readonly
Returns the value of attribute last_index.
Instance Method Summary collapse
- #first ⇒ Object
-
#initialize(a = nil, c = 0) ⇒ History
constructor
A new instance of History.
- #is_last? ⇒ Boolean
- #last ⇒ Object
- #max_index ⇒ Object
- #next ⇒ Object
- #previous ⇒ Object
- #push(item) ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(a = nil, c = 0) ⇒ History
Returns a new instance of History.
33 34 35 36 37 38 39 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 33 def initialize a=nil, c=0 #raise "Array passed to History cannot be nil" unless a #@max_index = a.size @array = a || [] @current_index = c @last_index = c end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array
29 30 31 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 29 def array @array end |
#current_index ⇒ Object
Returns the value of attribute current_index
29 30 31 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 29 def current_index @current_index end |
#last_index ⇒ Object (readonly)
Returns the value of attribute last_index.
30 31 32 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 30 def last_index @last_index end |
Instance Method Details
#first ⇒ Object
44 45 46 47 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 44 def first @current_index = 0 @array.first end |
#is_last? ⇒ Boolean
74 75 76 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 74 def is_last? @current_index == max_index() end |
#last ⇒ Object
40 41 42 43 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 40 def last @current_index = max_index @array.last end |
#max_index ⇒ Object
48 49 50 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 48 def max_index @array.size - 1 end |
#next ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 56 def next @last_index = @current_index if @current_index + 1 > max_index @current_index = 0 else @current_index += 1 end @array[@current_index] end |
#previous ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 65 def previous @last_index = @current_index if @current_index - 1 < 0 @current_index = max_index() else @current_index -= 1 end @array[@current_index] end |
#push(item) ⇒ Object
77 78 79 80 81 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 77 def push item $log.debug " XXX history push #{item} " if $log.debug? @array.push item @current_index = max_index end |
#up ⇒ Object
51 52 53 54 55 |
# File 'lib/rbcurse/core/util/bottomline.rb', line 51 def up item = @array[@current_index] previous return item end |