Class: Canis::History

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

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

#arrayObject

Returns the value of attribute array

Returns:

  • (Object)

    the current value of array



32
33
34
# File 'lib/canis/core/util/extras/bottomline.rb', line 32

def array
  @array
end

#current_indexObject

Returns the value of attribute current_index

Returns:

  • (Object)

    the current value of current_index



32
33
34
# File 'lib/canis/core/util/extras/bottomline.rb', line 32

def current_index
  @current_index
end

#last_indexObject (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

#firstObject



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

Returns:

  • (Boolean)


77
78
79
# File 'lib/canis/core/util/extras/bottomline.rb', line 77

def is_last?
  @current_index == max_index()
end

#lastObject



43
44
45
46
# File 'lib/canis/core/util/extras/bottomline.rb', line 43

def last
  @current_index = max_index
  @array.last
end

#max_indexObject



51
52
53
# File 'lib/canis/core/util/extras/bottomline.rb', line 51

def max_index
  @array.size - 1
end

#nextObject



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

#previousObject



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

#upObject



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