Class: Parsby::Backup
- Inherits:
-
StringIO
- Object
- StringIO
- Parsby::Backup
- Defined in:
- lib/parsby.rb
Instance Method Summary collapse
- #all ⇒ Object
- #back(n = back_size) ⇒ Object
- #back_lines ⇒ Object
- #col ⇒ Object
- #current_line ⇒ Object
- #rest_of_line ⇒ Object
- #with_saved_pos(&b) ⇒ Object
Instance Method Details
#all ⇒ Object
386 387 388 389 390 391 |
# File 'lib/parsby.rb', line 386 def all with_saved_pos do seek 0 read end end |
#back(n = back_size) ⇒ Object
395 396 397 398 399 400 |
# File 'lib/parsby.rb', line 395 def back(n = back_size) with_saved_pos do |saved| seek -n, IO::SEEK_CUR read n end end |
#back_lines ⇒ Object
408 409 410 |
# File 'lib/parsby.rb', line 408 def back_lines (back + rest_of_line).lines end |
#col ⇒ Object
412 413 414 |
# File 'lib/parsby.rb', line 412 def col back[/(?<=\A|\n).*\z/].length end |
#current_line ⇒ Object
416 417 418 419 420 421 |
# File 'lib/parsby.rb', line 416 def current_line with_saved_pos do seek(-col, IO::SEEK_CUR) readline.chomp end end |
#rest_of_line ⇒ Object
402 403 404 405 406 |
# File 'lib/parsby.rb', line 402 def rest_of_line with_saved_pos { readline } rescue EOFError "" end |
#with_saved_pos(&b) ⇒ Object
379 380 381 382 383 384 |
# File 'lib/parsby.rb', line 379 def with_saved_pos(&b) saved = pos b.call saved ensure seek saved end |