Class: RubyCurses::History

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

Instance Method Summary collapse

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

#arrayObject

Returns the value of attribute array

Returns:

  • (Object)

    the current value of array



29
30
31
# File 'lib/rbcurse/core/util/bottomline.rb', line 29

def array
  @array
end

#current_indexObject

Returns the value of attribute current_index

Returns:

  • (Object)

    the current value of current_index



29
30
31
# File 'lib/rbcurse/core/util/bottomline.rb', line 29

def current_index
  @current_index
end

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

#firstObject



44
45
46
47
# File 'lib/rbcurse/core/util/bottomline.rb', line 44

def first
  @current_index = 0
  @array.first
end

#is_last?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/rbcurse/core/util/bottomline.rb', line 74

def is_last?
  @current_index == max_index()
end

#lastObject



40
41
42
43
# File 'lib/rbcurse/core/util/bottomline.rb', line 40

def last
  @current_index = max_index
  @array.last
end

#max_indexObject



48
49
50
# File 'lib/rbcurse/core/util/bottomline.rb', line 48

def max_index
  @array.size - 1
end

#nextObject



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

#previousObject



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

#upObject



51
52
53
54
55
# File 'lib/rbcurse/core/util/bottomline.rb', line 51

def up
  item = @array[@current_index]
  previous
  return item
end