No commit activity in last 3 years
No release in over 3 years
Logs the progress of an operation, with estimated completion time.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 13.0.6
~> 3.12.0
 Project Readme

ProgressPrinter Gem Version

Logs the progress of an operation, with estimated completion time.

Installation

When using Bundler, add this to your project's Gemfile:

gem 'progress_printer'

Otherwise, install it with the gem command:

$ gem install progress_printer

Already in a console?

ProgressPrinter is in a single file with no dependencies, so you're able to copy/paste the entire file into an irb session, and then immediately use ProgressPrinter.new (see below). The raw source to copy is available here:

https://raw.githubusercontent.com/justincampbell/progress_printer/master/lib/progress_printer.rb

Usage

Basic Usage

A ProgressPrinter must be created, started, and finished. Use #increment within your operation to increment the progress.

require 'progress_printer'

printer = ProgressPrinter.new(name: "Counting", total: 250)
printer.start
250.times { sleep 0.05; printer.increment }
printer.finish

Output:

Counting:   0/250   0% calculating...
Counting: 100/250  40% ~8s
Counting: 200/250  80% ~2s
Counting: 250/250 100% 14s total

You can also achieve the same results by using .wrap or #wrap:

ProgressPrinter.wrap(name: "Counting", total: 250) do |progress|
  250.times { sleep 0.05; progress.increment }
end
printer = ProgressPrinter.new(name: "Counting", total: 250)
printer.wrap do |progress|
  250.times { sleep 0.05; progress.increment }
end

Arguments

  • total - The total number of iterations expected. If this is omitted, estimated completion time will not be shown.
  • name - A string to display next to each printed line. This helps identify the current operation, or the specific progress printer if using multiple.
  • every (Default: 100) - How many iterations should pass in between printing a line.
  • out (Default: $stdout) - An object responding to #puts for printing the progress to.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/justincampbell/progress_printer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.