Class: Parsby::Backup

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

Instance Method Summary collapse

Instance Method Details

#allObject



410
411
412
413
414
415
# File 'lib/parsby.rb', line 410

def all
  with_saved_pos do
    seek 0
    read
  end
end

#back(n = back_size) ⇒ Object



419
420
421
422
423
424
# File 'lib/parsby.rb', line 419

def back(n = back_size)
  with_saved_pos do |saved|
    seek -n, IO::SEEK_CUR
    read n
  end
end

#back_linesObject



432
433
434
# File 'lib/parsby.rb', line 432

def back_lines
  (back + rest_of_line).lines
end

#colObject



436
437
438
# File 'lib/parsby.rb', line 436

def col
  back[/(?<=\A|\n).*\z/].length
end

#current_lineObject



440
441
442
443
444
445
# File 'lib/parsby.rb', line 440

def current_line
  with_saved_pos do
    seek(-col, IO::SEEK_CUR)
    readline.chomp
  end
end

#rest_of_lineObject



426
427
428
429
430
# File 'lib/parsby.rb', line 426

def rest_of_line
  with_saved_pos { readline }
rescue EOFError
  ""
end

#with_saved_pos(&b) ⇒ Object



403
404
405
406
407
408
# File 'lib/parsby.rb', line 403

def with_saved_pos(&b)
  saved = pos
  b.call saved
ensure
  seek saved
end