class Archive
This class provides a useful object to store the command history of linmeric
- Author
-
Massimiliano Dal Mas (max.codeware@gmail.com)
- License
-
Distributed under MIT license
Public Class Methods
new()
click to toggle source
Creates a new Archive objects
# File lib/linmeric/Archive.rb, line 12 def initialize @myArray = [] @i = 0 end
Public Instance Methods
next_()
click to toggle source
Returns the next item compared to the pointer position
-
*returns*: saved object; “” if the pointer is already at the
end of the Archive
# 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
previous()
click to toggle source
Returns the previous item compared to the pointer position
-
*returns*: saved object; “” if the pointer is already at the
beginning of the archive
# 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)
click to toggle source
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)
# 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
top()
click to toggle source
Moves the pointer to the top of the archive (the last element inserted)
# File lib/linmeric/Archive.rb, line 64 def top @i = @myArray.size end