Class: Parsby::Backup

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

Instance Method Summary collapse

Instance Method Details

#allObject



385
386
387
388
389
390
# File 'lib/parsby.rb', line 385

def all
  with_saved_pos do
    seek 0
    read
  end
end

#back(n = back_size) ⇒ Object



394
395
396
397
398
399
# File 'lib/parsby.rb', line 394

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

#back_linesObject



407
408
409
# File 'lib/parsby.rb', line 407

def back_lines
  (back + rest_of_line).lines
end

#colObject



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

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

#current_lineObject



415
416
417
418
419
420
# File 'lib/parsby.rb', line 415

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

#rest_of_lineObject



401
402
403
404
405
# File 'lib/parsby.rb', line 401

def rest_of_line
  with_saved_pos { readline }
rescue EOFError
  ""
end

#with_saved_pos(&b) ⇒ Object



378
379
380
381
382
383
# File 'lib/parsby.rb', line 378

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