Brings the great ruby-progressbar to Enumerable
.
Usage
This gem adds the method Enumerable#with_progress
.
Calling with_progress
displays a progress bar while the iteration takes place.
It uses the ruby-progressbar gem and accepts the same options.
In Ruby 2.0+, most enumerables return a size, so with_progress
uses that to deduce the total
, there's no need to specify it:
42.times.with_progress { do_something }
# Will create the progress bar, provide the {total: 42} option
# (in Ruby 2.0+) and call increment after each do_something
For Ruby older than 2.0.0, some enumerators won't work, so progression will only show the elapsed time but won't be able to guess the remaining time. You can require some backports to improve the situation, for example:
require 'backports/2.0.0/range/size' (10...42).with_progress { do_something } # will calculate the remaining time, even in old Rubies
Installation
Add this line to your application's Gemfile:
gem 'with_progress'
And then execute:
$ bundle
Or install it yourself as:
$ gem install with_progress
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request