Skip to content

Instantly share code, notes, and snippets.

@snelson82
Last active June 15, 2021 15:07
Show Gist options
  • Save snelson82/afb39f27a848c0f4abd52e290afaf52e to your computer and use it in GitHub Desktop.
Save snelson82/afb39f27a848c0f4abd52e290afaf52e to your computer and use it in GitHub Desktop.
Progress bar added to CSV for output while parsing
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