Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

ProgressPrinter Gem Version Build Status

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?

Progress Printer is in a single 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.

About

Ruby gem which logs the progress of an operation, with estimated completion time

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.