Class: Tkri::History

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

Instance Method Summary collapse

Constructor Details

#initializeHistory

Returns a new instance of History.



199
200
201
202
# File 'lib/tkri.rb', line 199

def initialize
  @arr = []
  @current = -1
end

Instance Method Details

#add(entry) ⇒ Object



229
230
231
232
233
234
# File 'lib/tkri.rb', line 229

def add(entry)
  @current += 1
  @arr[@current] = entry
  # Adding an entry removes all entries in the "future".
  @arr.slice!(@current + 1, @arr.size)
end

#at_beginningObject



236
237
238
# File 'lib/tkri.rb', line 236

def at_beginning
  @current <= 0
end

#at_endObject



240
241
242
# File 'lib/tkri.rb', line 240

def at_end
  @current == @arr.size - 1;
end

#backObject



216
217
218
219
220
221
# File 'lib/tkri.rb', line 216

def back
  if @current > 0
    @current -= 1
  end
  current
end

#currentObject



208
209
210
211
212
213
214
# File 'lib/tkri.rb', line 208

def current
  if @current >= 0
    @arr[@current]
  else
    nil
  end
end

#forewardObject



223
224
225
226
227
# File 'lib/tkri.rb', line 223

def foreward
  if @current < @arr.size - 1
    @current += 1
  end
end

#sizeObject



204
205
206
# File 'lib/tkri.rb', line 204

def size
  @arr.size
end