Class: SpinalTap::History

Inherits:
Object
  • Object
show all
Defined in:
lib/spinal_tap/history.rb

Constant Summary collapse

MAX_LINES =
100

Instance Method Summary collapse

Constructor Details

#initializeHistory

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

#allObject



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

#currentObject



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_forwardObject



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

Returns:

  • (Boolean)


44
45
46
# File 'lib/spinal_tap/history.rb', line 44

def last?
  return @history_pos >= @history.length - 1
end

#nextObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/spinal_tap/history.rb', line 31

def next?
  return @history_pos < @history.length - 1
end

#previousObject



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

Returns:

  • (Boolean)


18
19
20
# File 'lib/spinal_tap/history.rb', line 18

def previous?
  return @history_pos > 0
end