Class: SpinalTap::History
- Inherits:
-
Object
- Object
- SpinalTap::History
- Defined in:
- lib/spinal_tap/history.rb
Constant Summary collapse
- MAX_LINES =
100
Instance Method Summary collapse
- #all ⇒ Object
- #append(cmd_line) ⇒ Object
- #current ⇒ Object
- #fast_forward ⇒ Object
-
#initialize ⇒ History
constructor
A new instance of History.
- #last? ⇒ Boolean
- #next ⇒ Object
- #next? ⇒ Boolean
- #previous ⇒ Object
- #previous? ⇒ Boolean
Constructor Details
#initialize ⇒ History
Returns a new instance of History.
6 7 8 9 |
# File 'lib/spinal_tap/history.rb', line 6 def initialize @history = [''] @history_pos = 0 end |
Instance Method Details
#all ⇒ Object
59 60 61 |
# File 'lib/spinal_tap/history.rb', line 59 def all return @history[0..-2].map { |e| e.clone } end |
#append(cmd_line) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spinal_tap/history.rb', line 48 def append(cmd_line) @history.pop @history << cmd_line.clone @history << '' trim fast_forward return true end |
#current ⇒ Object
11 12 13 14 15 16 |
# File 'lib/spinal_tap/history.rb', line 11 def current cur = @history[@history_pos] cur = cur.clone unless last? return cur end |
#fast_forward ⇒ Object
63 64 65 66 67 |
# File 'lib/spinal_tap/history.rb', line 63 def fast_forward @history_pos = @history.length - 1 return current end |
#last? ⇒ Boolean
44 45 46 |
# File 'lib/spinal_tap/history.rb', line 44 def last? return @history_pos >= @history.length - 1 end |
#next ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/spinal_tap/history.rb', line 35 def next if next? @history_pos += 1 return current else return false end end |
#next? ⇒ Boolean
31 32 33 |
# File 'lib/spinal_tap/history.rb', line 31 def next? return @history_pos < @history.length - 1 end |
#previous ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/spinal_tap/history.rb', line 22 def previous if previous? @history_pos -= 1 return current else return false end end |
#previous? ⇒ Boolean
18 19 20 |
# File 'lib/spinal_tap/history.rb', line 18 def previous? return @history_pos > 0 end |