Class: Warg::Console::History::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, cursor_position) ⇒ Entry

Returns a new instance of Entry.



345
346
347
348
349
350
351
352
353
354
# File 'lib/warg.rb', line 345

def initialize(content, cursor_position)
  @content = content

  @row_number = cursor_position.row
  @column_number = cursor_position.column

  @text = @content.to_s
  @newline_count = @content.newline_count
  @last_line_length = @content.last_line_length
end

Instance Attribute Details

#column_numberObject

Returns the value of attribute column_number.



337
338
339
# File 'lib/warg.rb', line 337

def column_number
  @column_number
end

#contentObject (readonly)

Returns the value of attribute content.



338
339
340
# File 'lib/warg.rb', line 338

def content
  @content
end

#last_line_lengthObject (readonly)

Returns the value of attribute last_line_length.



339
340
341
# File 'lib/warg.rb', line 339

def last_line_length
  @last_line_length
end

#newline_countObject (readonly)

Returns the value of attribute newline_count.



341
342
343
# File 'lib/warg.rb', line 341

def newline_count
  @newline_count
end

#next_entryObject

Returns the value of attribute next_entry.



340
341
342
# File 'lib/warg.rb', line 340

def next_entry
  @next_entry
end

#previous_entryObject

Returns the value of attribute previous_entry.



342
343
344
# File 'lib/warg.rb', line 342

def previous_entry
  @previous_entry
end

#row_numberObject

Returns the value of attribute row_number.



343
344
345
# File 'lib/warg.rb', line 343

def row_number
  @row_number
end

Instance Method Details

#end_columnObject



369
370
371
372
373
374
375
376
377
# File 'lib/warg.rb', line 369

def end_column
  value = 1 + @content.last_line_length

  if newline_count.zero?
    value += @column_number
  end

  value
end

#end_rowObject



365
366
367
# File 'lib/warg.rb', line 365

def end_row
  @row_number + newline_count
end

#inspectObject



383
384
385
# File 'lib/warg.rb', line 383

def inspect
  %{#<#{self.class.name} row_number=#{row_number} column_number=#{column_number} content=#{content.inspect}>}
end

#newline_count_diffObject



361
362
363
# File 'lib/warg.rb', line 361

def newline_count_diff
  @content.newline_count - @newline_count
end

#sync!Object



356
357
358
359
# File 'lib/warg.rb', line 356

def sync!
  @text = @content.to_s
  @last_line_length = @content.last_line_length
end

#to_sObject



379
380
381
# File 'lib/warg.rb', line 379

def to_s
  @text.dup
end