Last active
June 15, 2021 15:07
-
-
Save snelson82/afb39f27a848c0f4abd52e290afaf52e to your computer and use it in GitHub Desktop.
Progress bar added to CSV for output while parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'progress_bar' | |
# Extends CSV class to include progress bar enhancement | |
class CSV | |
module ProgressBar | |
def progress_bar | |
::ProgressBar.new(@io.size, :bar, :counter, :percentage, :elapsed, :eta) | |
end | |
def each | |
progress_bar = self.progress_bar | |
super do |row| | |
yield row | |
progress_bar.count = pos | |
progress_bar.increment!(0) | |
end | |
end | |
end | |
class WithProgressBar < CSV | |
include ProgressBar | |
end | |
def self.with_progress_bar | |
WithProgressBar | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment