Class: Warg::Console::History

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

Defined Under Namespace

Classes: Entry, FirstEntry

Instance Method Summary collapse

Constructor Details

#initializeHistory

Returns a new instance of History.


278
279
280
# File 'lib/warg.rb', line 278

def initialize
  @head = FirstEntry.new
end

Instance Method Details

#append(content, at: cursor_position) ⇒ Object


282
283
284
285
286
287
288
289
# File 'lib/warg.rb', line 282

def append(content, at: cursor_position)
  entry = Entry.new(content, at)

  entry.previous_entry = @head
  @head.next_entry     = entry

  @head = entry
end

#find_entry_for(content) ⇒ Object


291
292
293
294
295
296
297
298
299
# File 'lib/warg.rb', line 291

def find_entry_for(content)
  current_entry = @head

  until current_entry.previous_entry.nil? || current_entry.content == content
    current_entry = current_entry.previous_entry
  end

  current_entry
end

#inspectObject


301
302
303
# File 'lib/warg.rb', line 301

def inspect
  %{#<#{self.class.name} head=#{@head}>}
end