• Stars
    star
    68
  • Rank 441,847 (Top 9 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Class to show progress during script run

Gem Version Build Status Rubocop Code Climate Depfu Inch CI

progress

Show progress during console script run.

Installation

gem install progress

Usage

1000.times_with_progress('Counting to 1000') do |i|
  # do something with i
end

or without title:

1000.times_with_progress do |i|
  # do something with i
end

With array:

[1, 2, 3].with_progress('1…2…3').each do |i|
  # still counting
end

.each is optional:

[1, 2, 3].with_progress('1…2…3') do |i|
  # =||=
end

Nested progress

(1..10).with_progress('Outer').map do |a|
  (1..10).with_progress('Middle').map do |b|
    (1..10).with_progress('Inner').map do |c|
      # do something with a, b and c
    end
  end
end

You can also show note:

[1, 2, 3].with_progress do |i|
  Progress.note = i
  sleep 5
end

You can use any enumerable method:

[1, 2, 3].with_progress.map{ |i| 'do stuff' }
[1, 2, 3].with_progress.each_cons(3){ |i| 'do stuff' }
[1, 2, 3].with_progress.each_slice(2){ |i| 'do stuff' }
# …

Any enumerable will work:

(1..100).with_progress('Wait') do |i|
  # ranges are good
end

Dir.new('.').with_progress do |path|
  # check path
end

NOTE: progress gets number of objects using length, size, to_a.length or just inject and if used on objects which needs rewind (like opened File), cycle itself will not work.

Use simple blocks:

symbols = []
Progress.start('Input 100 symbols', 100) do
  while symbols.length < 100
    input = gets.scan(/\S/)
    symbols += input
    Progress.step input.length
  end
end

or just

symbols = []
Progress('Input 100 symbols', 100) do
  while symbols.length < 100
    input = gets.scan(/\S/)
    symbols += input
    Progress.step input.length
  end
end

NOTE: you will get WRONG progress if you use something like this:

10.times_with_progress('A') do |time|
  10.times_with_progress('B') do
    # code
  end
  10.times_with_progress('C') do
    # code
  end
end

But you can use this:

10.times_with_progress('A') do |time|
  Progress.step 5 do
    10.times_with_progress('B') do
      # code
    end
  end
  Progress.step 5 do
    10.times_with_progress('C') do
      # code
    end
  end
end

Or if you know that B runs 9 times faster than C:

10.times_with_progress('A') do |time|
  Progress.step 1 do
    10.times_with_progress('B') do
      # code
    end
  end
  Progress.step 9 do
    10.times_with_progress('C') do
      # code
    end
  end
end

Copyright

Copyright (c) 2008-2021 Ivan Kuchin. See LICENSE.txt for details.

More Repositories

1

image_optim

Optimize images using multiple utilities
Ruby
1,503
star
2

blueutil

CLI for bluetooth on OSX: power, discoverable state, list, inquire devices, connect, info, …
Objective-C
916
star
3

dump

Rails app rake and capistrano tasks to create and restore dumps of database and assets
Ruby
89
star
4

image_size

measure image size using pure Ruby (by Keisuke Minami)
Ruby
83
star
5

image_optim_pack

Precompiled binaries for image_optim
Ruby
77
star
6

pHash

Ruby interface to pHash
Ruby
60
star
7

image_optim_rails

Optimize rails assets using image_optim
Ruby
53
star
8

in_threads

Run all possible enumerable methods in concurrent/parallel threads
Ruby
37
star
9

sdoc_all

sdoc_all is no longer maintained, try doc gem
Ruby
15
star
10

random_text

Class to make access to http://vesna.yandex.ru/ and http://lipsum.com/ easier
Ruby
10
star
11

output_compression

gzip compression output - it is just a mirror with applied patches
Ruby
9
star
12

rbenv-update-rubies

Update rbenv ruby versions
Shell
7
star
13

phamilie

Compute image fingerprints and similarity
Ruby
7
star
14

doc

Command line tool to get searchable documentation for ruby, rails, gems, plugins and other ruby related code in one place
Ruby
6
star
15

free_mem

Free memory on mac
C
6
star
16

tms

Time Machine Status
Ruby
5
star
17

upload_column

upload_column 0.2.1 with some fixes
Ruby
5
star
18

FinderPatch

Finder fixes: select next after trashing, label shortcuts, open in terminal, open in textmate
Objective-C
5
star
19

fspath-mac

FSPath methods for mac
Objective-C
5
star
20

fspath

Better than Pathname
Ruby
4
star
21

spec_routes_tester

Plugin with class that allows you much easier routes testing with rspec
Ruby
4
star
22

mate

TextMate project builder and TextMate 2 properties builder using git ignores for exclusions
Ruby
4
star
23

extended_form_helper

Helper methods to ease form creation
Ruby
4
star
24

cache_method

cache method result in attribute
Ruby
3
star
25

contacts

store a lot of contacts in one text field with validation and link creation
Ruby
3
star
26

data_columns

Store multiple columns in serialized data column
Ruby
3
star
27

rbenv-around-install

Run scripts before and after installing ruby using ruby-build
Shell
3
star
28

fspath-xattr

FSPath methods xattr and lxattr to work with extended attributes using ffi-xattr gem
Ruby
3
star
29

set_icon

set/unset custom icon for file
Objective-C
3
star
30

access

Plugin for writing allow/deny rules in controllers
Ruby
3
star
31

growler

Growl like messages in rails app
JavaScript
2
star
32

remove_stale_gems

remove unused gems
Ruby
2
star
33

toy.github.com

toy.github.com
JavaScript
2
star
34

toy

✨special✨ repository
2
star
35

TmCleanSave

TextMate bundle which removes extra whitespace and fixes tabs when saving file
C
2
star
36

russian

String methods to ease work with russian language
Ruby
2
star
37

ui

repository to easily distribute compiled ui reference
PHP
2
star
38

link.app

Create hardlink/symlink (alt to force symlink) for items selected in Finder
Objective-C
2
star
39

newTabHere.app

open new Terminal tab next to current with same dir
Objective-C
2
star
40

box-for-rubygems

Shell
1
star
41

restartable

Run code, Ctrl-C to restart, two Ctrl-C to stop
Ruby
1
star
42

as

repository to easily distribute compiled actionscript reference
JavaScript
1
star
43

rbenv-with

rbenv with 2.4
Shell
1
star
44

simple_scaffold

simple_scaffold
1
star
45

rb

repository to easily distribute compiled rb reference
JavaScript
1
star
46

Appscript

clone of Obj-C appscript
Objective-C
1
star
47

TerminalPatch

New Terminal tab/window with same dir
Objective-C
1
star
48

rake-gem-ghost

Help gem developers to test created gems — creates symlink from installed gem to current folder.
Ruby
1
star
49

SilverService

fork of application to make mac os x services from unix commands
Objective-C
1
star
50

fix_html

helper to make html valid
Ruby
1
star
51

server_dotfiles

server dotfiles
1
star
52

xcode

Rake tasks to help packaging products made with Xcode.
Ruby
1
star
53

rails_seeder

Helpers to generate test data
Ruby
1
star
54

rb-appscript

because it still works even for ruby 3.0
Ruby
1
star