Class: Canis::History
- Defined in:
- lib/canis/core/util/extras/bottomline.rb
Overview
— History class {{{ 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
Enable field history on UP and DOWN during rb_getstr
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.
36 37 38 39 40 41 42 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 36 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
32 33 34 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 32 def array @array end |
#current_index ⇒ Object
Returns the value of attribute current_index
32 33 34 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 32 def current_index @current_index end |
#last_index ⇒ Object (readonly)
Returns the value of attribute last_index.
33 34 35 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 33 def last_index @last_index end |
Instance Method Details
#first ⇒ Object
47 48 49 50 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 47 def first @current_index = 0 @array.first end |
#is_last? ⇒ Boolean
77 78 79 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 77 def is_last? @current_index == max_index() end |
#last ⇒ Object
43 44 45 46 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 43 def last @current_index = max_index @array.last end |
#max_index ⇒ Object
51 52 53 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 51 def max_index @array.size - 1 end |
#next ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 59 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
68 69 70 71 72 73 74 75 76 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 68 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
80 81 82 83 84 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 80 def push item $log.debug " XXX history push #{item} " if $log.debug? @array.push item @current_index = max_index end |
#up ⇒ Object
54 55 56 57 58 |
# File 'lib/canis/core/util/extras/bottomline.rb', line 54 def up item = @array[@current_index] previous return item end |