Class: Archive

Inherits:
Object
  • Object
show all
Defined in:
lib/linmeric/Archive.rb

Overview

This class provides a useful object to store the command history of linmeric

Author

Massimiliano Dal Mas ([email protected])

License

Distributed under MIT license

Instance Method Summary collapse

Constructor Details

#initializeArchive

Creates a new Archive objects



12
13
14
15
# File 'lib/linmeric/Archive.rb', line 12

def initialize
  @myArray = []
  @i = 0
end

Instance Method Details

#next_Object

Returns the next item compared to the pointer position

  • returns: saved object; “” if the pointer is already at the

end of the Archive



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/linmeric/Archive.rb', line 51

def next_
  if  @i < (@myArray.size - 1) 
    @i += 1
    return @myArray[@i].clone
  else
    @i = @myArray.size
    return ""
  end
  @i = @myArray.size
  return ""
end

#previousObject

Returns the previous item compared to the pointer position

  • returns: saved object; “” if the pointer is already at the

beginning of the archive



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/linmeric/Archive.rb', line 35

def previous
  if not @i == 0 then
    @i -= 1
    return @myArray[@i].clone
  else
    @i = 0
    return ""
  end
  @i = 0
  return ""
end

#store(str) ⇒ Object

Adds a new item to the archive (it keeps the last 20 items which have been inserted).

  • argument: item to be added (mainly a String)



21
22
23
24
25
26
27
28
29
# File 'lib/linmeric/Archive.rb', line 21

def store(str)
  if @myArray.size == 20
    @myArray = @myArray[1...@myArray.size] + [str]
    # @i = @myArray.size
  else
    @myArray[@myArray.size] = str
    @i = @myArray.size
  end
end

#topObject

Moves the pointer to the top of the archive (the last element inserted)



64
65
66
# File 'lib/linmeric/Archive.rb', line 64

def top
  @i = @myArray.size
end