tqdm-ruby
tqdm-ruby is a small utility to show a progress indicator while iterating through an Enumerable object.
It is a port of the excellent tdqm library for python: https://github.com/tqdm/tqdm.
Call #tqdm on any Enumerable
, which enhances the object so that iterating over it will produce an animated progress bar on $stderr
.
require 'tqdm'
(0...1000).tqdm.each {|x| sleep 0.01 }
The default output looks like this:
|####------| 492/1000 49% [elapsed: 00:05 left: 00:05, 88.81 iters/sec]
It works equally well from within pry and Jupyter notebooks.
Install
Add this line to your application's Gemfile
:
gem 'tqdm'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tqdm
Usage
All Enumerable
objects gain access to the #tqdm
method, which returns an enhanced object wherein any iteration (by calling #each
or any of its relatives, e.g., #each_with_index
, #each_with_object
, etc.) produces an animated progress bar on $stderr.
require 'tqdm'
(0...100).tqdm.each {|x| sleep 0.01 }
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