lib/tracksperanto/progressive_io.rb in tracksperanto-2.1.1 vs lib/tracksperanto/progressive_io.rb in tracksperanto-2.2.0
- old
+ new
@@ -1,7 +1,8 @@
# Used for IO objects that need to report the current offset at each operation that changes the said offset
-# (useful for building progress bars that report on a file read operation)
+# (useful for building progress bars that report on a file read operation). Pass the actual IO and a block to
+# report progress to the constructor.
class Tracksperanto::ProgressiveIO < DelegateClass(IO)
include Tracksperanto::Returning
# Get or set the total size of the contained IO. If the passed IO is a File object
# the size will be preset automatically
@@ -12,9 +13,10 @@
__setobj__(with_file)
@total_size = with_file.stat.size if with_file.respond_to?(:stat)
@progress_block = blk.to_proc if blk
end
+ # Report offset at each line
def each(sep_string = $/, &blk)
# Report offset at each call of the iterator
result = super(sep_string) do | line |
yield(line)
notify_read
\ No newline at end of file