progress 3.3.2 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop.yml +33 -12
- data/.travis.yml +15 -12
- data/CHANGELOG.markdown +273 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.markdown +107 -81
- data/lib/progress.rb +2 -0
- data/lib/progress/active_record.rb +2 -0
- data/lib/progress/beeper.rb +2 -0
- data/lib/progress/class_methods.rb +25 -9
- data/lib/progress/elapsed_time.rb +26 -0
- data/lib/progress/enumerable.rb +2 -0
- data/lib/progress/eta.rb +10 -3
- data/lib/progress/integer.rb +2 -0
- data/lib/progress/kernel.rb +4 -1
- data/lib/progress/with_progress.rb +7 -13
- data/progress.gemspec +12 -5
- data/spec/progress/elapsed_time_spec.rb +13 -0
- data/spec/progress_spec.rb +82 -33
- metadata +21 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cdce3b680bc7e08cda708708d4058f6cddd399469463d57adfeb576ce7436bd7
|
4
|
+
data.tar.gz: 699601431481e0159b0f48102a879e3bb8e47f473bedd25478002cbc55856225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84757caa1fa6d3e7e6f4a1e78d086d3494ae991021178fdbd454b05ed81b16b3ef6439719e9e3b6c37549c9fb9bc3f6420232b2fcb5f68f684d5655c1245bd4b
|
7
|
+
data.tar.gz: e1f40e3b1a84f4f8cea4e29ba798f136ed72e5b7a2e978dde51c86fd0c28cbcf4c695557b8920649948d0b6c6d5299eccde2c6b83e59fbfb7d51600b76d88651
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
3
|
- '*.gemspec'
|
4
|
+
NewCops: enable
|
5
|
+
TargetRubyVersion: 2.4
|
4
6
|
|
5
7
|
Layout/AccessModifierIndentation:
|
6
8
|
EnforcedStyle: outdent
|
@@ -11,17 +13,21 @@ Layout/CaseIndentation:
|
|
11
13
|
Layout/DotPosition:
|
12
14
|
EnforcedStyle: trailing
|
13
15
|
|
14
|
-
Layout/
|
16
|
+
Layout/EndAlignment:
|
17
|
+
EnforcedStyleAlignWith: variable
|
18
|
+
|
19
|
+
Layout/FirstHashElementIndentation:
|
15
20
|
EnforcedStyle: consistent
|
16
21
|
|
17
22
|
Layout/SpaceBeforeBlockBraces:
|
18
23
|
EnforcedStyle: no_space
|
24
|
+
EnforcedStyleForEmptyBraces: no_space
|
19
25
|
|
20
26
|
Layout/SpaceInsideHashLiteralBraces:
|
21
27
|
EnforcedStyle: no_space
|
22
28
|
|
23
|
-
Lint/
|
24
|
-
|
29
|
+
Lint/RedundantRequireStatement:
|
30
|
+
Enabled: false
|
25
31
|
|
26
32
|
Metrics/AbcSize:
|
27
33
|
Max: 30
|
@@ -43,17 +49,14 @@ Metrics/ModuleLength:
|
|
43
49
|
Max: 200
|
44
50
|
|
45
51
|
Metrics/PerceivedComplexity:
|
46
|
-
Max:
|
52
|
+
Max: 11
|
47
53
|
|
48
|
-
|
54
|
+
Style/AccessorGrouping:
|
49
55
|
Enabled: false
|
50
56
|
|
51
57
|
Style/Alias:
|
52
58
|
EnforcedStyle: prefer_alias_method
|
53
59
|
|
54
|
-
Style/BracesAroundHashParameters:
|
55
|
-
Enabled: false
|
56
|
-
|
57
60
|
Style/DoubleNegation:
|
58
61
|
Enabled: false
|
59
62
|
|
@@ -63,23 +66,41 @@ Style/EmptyCaseCondition:
|
|
63
66
|
Style/Encoding:
|
64
67
|
Enabled: false
|
65
68
|
|
66
|
-
Style/
|
67
|
-
|
69
|
+
Style/FormatStringToken:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/HashEachMethods:
|
73
|
+
Enabled: true
|
74
|
+
|
75
|
+
Style/HashTransformKeys:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Style/HashTransformValues:
|
79
|
+
Enabled: false
|
68
80
|
|
69
81
|
Style/IfUnlessModifier:
|
70
|
-
|
82
|
+
Enabled: false
|
71
83
|
|
72
84
|
Style/NumericPredicate:
|
73
85
|
Enabled: false
|
74
86
|
|
87
|
+
Style/OptionalBooleanParameter:
|
88
|
+
Enabled: false
|
89
|
+
|
75
90
|
Style/ParallelAssignment:
|
76
91
|
Enabled: false
|
77
92
|
|
93
|
+
Style/SafeNavigation:
|
94
|
+
Enabled: false
|
95
|
+
|
78
96
|
Style/Semicolon:
|
79
97
|
AllowAsExpressionSeparator: true
|
80
98
|
|
81
99
|
Style/TrailingCommaInArguments:
|
82
100
|
EnforcedStyleForMultiline: no_comma
|
83
101
|
|
84
|
-
Style/
|
102
|
+
Style/TrailingCommaInArrayLiteral:
|
103
|
+
EnforcedStyleForMultiline: comma
|
104
|
+
|
105
|
+
Style/TrailingCommaInHashLiteral:
|
85
106
|
EnforcedStyleForMultiline: comma
|
data/.travis.yml
CHANGED
@@ -1,23 +1,26 @@
|
|
1
|
-
|
1
|
+
dist: xenial
|
2
2
|
language: ruby
|
3
3
|
before_install:
|
4
|
-
- gem
|
4
|
+
- gem install bundler || gem install bundler --version '< 2'
|
5
5
|
rvm:
|
6
|
-
- '1.8.7-p371'
|
7
6
|
- '1.9.3-p551'
|
8
7
|
- '2.0.0-p648'
|
9
8
|
- '2.1.10'
|
10
|
-
- '2.2.
|
11
|
-
- '2.3.
|
12
|
-
- '2.4.
|
13
|
-
- '
|
14
|
-
- '
|
9
|
+
- '2.2.10'
|
10
|
+
- '2.3.8'
|
11
|
+
- '2.4.10'
|
12
|
+
- '2.5.8'
|
13
|
+
- '2.6.6'
|
14
|
+
- '2.7.2'
|
15
|
+
- '3.0.0'
|
16
|
+
- 'jruby-9.1.17.0'
|
17
|
+
- 'jruby-9.2.14.0'
|
15
18
|
script: bundle exec rspec
|
16
19
|
matrix:
|
17
20
|
include:
|
18
|
-
- env: RUBOCOP
|
19
|
-
rvm: '2.4.
|
21
|
+
- env: RUBOCOP=1
|
22
|
+
rvm: '2.4.10'
|
20
23
|
script: bundle exec rubocop
|
21
|
-
- env: CHECK_RUBIES
|
22
|
-
rvm: '2.4.
|
24
|
+
- env: CHECK_RUBIES=1
|
25
|
+
rvm: '2.4.10'
|
23
26
|
script: bundle exec travis_check_rubies
|
data/CHANGELOG.markdown
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
# ChangeLog
|
2
|
+
|
3
|
+
## unreleased
|
4
|
+
|
5
|
+
## v3.6.0 (2021-04-02)
|
6
|
+
|
7
|
+
* Use `Process.clock_gettime` instead of `Time.now` which is faster and should give proper estimates even if sleeping in the middle [#13](https://github.com/toy/progress/issues/13) [@toy](https://github.com/toy)
|
8
|
+
|
9
|
+
## v3.5.2 (2019-07-14)
|
10
|
+
|
11
|
+
* Remove deprecated `rubyforge_project` attribute from gemspec [rubygems/rubygems#2436](https://github.com/rubygems/rubygems/pull/2436) [@toy](https://github.com/toy)
|
12
|
+
|
13
|
+
## v3.5.1 (2019-05-25)
|
14
|
+
|
15
|
+
* Enable frozen string literals [@toy](https://github.com/toy)
|
16
|
+
|
17
|
+
## v3.5.0 (2018-10-19)
|
18
|
+
|
19
|
+
* Add `Progress.without_beeper` for stopping periodical refresh of progress/eta for the duration of the block [@toy](https://github.com/toy)
|
20
|
+
|
21
|
+
## v3.4.0 (2017-10-11)
|
22
|
+
|
23
|
+
* Remove special handling for CSV in ruby 1.8 [@toy](https://github.com/toy)
|
24
|
+
* Set minimum ruby version to 1.9.3 [@toy](https://github.com/toy)
|
25
|
+
* Support `Enumerable#each_with_index` which stopped working since [45435b3](https://github.com/toy/progress/commit/45435b31ae0f9ad42255d9105d264f5fe9722c88) ([v3.2.2](#v322-2016-07-27)), not compatible with ruby 1.8 [#9](https://github.com/toy/progress/pull/9) [@amatsuda](https://github.com/amatsuda)
|
26
|
+
|
27
|
+
## v3.3.2 (2017-10-09)
|
28
|
+
|
29
|
+
* Support `Enumerable#each_with_index` which stopped working since [45435b3](https://github.com/toy/progress/commit/45435b31ae0f9ad42255d9105d264f5fe9722c88) ([v3.2.2](#v322-2016-07-27)), compatible with ruby 1.8 [#10](https://github.com/toy/progress/pull/10) [@amatsuda](https://github.com/amatsuda)
|
30
|
+
|
31
|
+
## v3.3.1 (2017-02-22)
|
32
|
+
|
33
|
+
* Fix for jruby raising wrong exception when checking if io is seekable [@toy](https://github.com/toy)
|
34
|
+
|
35
|
+
## v3.3.0 (2017-01-30)
|
36
|
+
|
37
|
+
* Add public setter for `io` and make `io` and `io_tty?` methods public [#8](https://github.com/toy/progress/issues/8) [@toy](https://github.com/toy)
|
38
|
+
|
39
|
+
## v3.2.2 (2016-07-27)
|
40
|
+
|
41
|
+
* Fix block arguments for `Hash` in ruby < 1.9 [@toy](https://github.com/toy)
|
42
|
+
|
43
|
+
## v3.2.1 (2016-07-26)
|
44
|
+
|
45
|
+
* Fix `respond_to?` for non existing methods in ruby < 1.9 [@toy](https://github.com/toy)
|
46
|
+
|
47
|
+
## v3.2.0 (2016-07-26)
|
48
|
+
|
49
|
+
* Provide `respond_to_missing?` instead of `respond_to?` in `WithProgress` [@toy](https://github.com/toy)
|
50
|
+
|
51
|
+
## v3.1.1 (2016-01-11)
|
52
|
+
|
53
|
+
* Fix `Thread.exclusive` deprecation in Ruby 2.3.0 [#4](https://github.com/toy/progress/pull/4) [@katsuma](https://github.com/katsuma)
|
54
|
+
|
55
|
+
## v3.1.0 (2014-12-22)
|
56
|
+
|
57
|
+
* Add handling for CSV in ruby 1.8 [@toy](https://github.com/toy)
|
58
|
+
* Fix getting total for progress on `Range` [@toy](https://github.com/toy)
|
59
|
+
* Use `StringIO` for `String` progress and `pos`/`size` for `IO` progress to not convert to array before progress [@toy](https://github.com/toy)
|
60
|
+
* Set `WithProgress` title to `nil` by default [@toy](https://github.com/toy)
|
61
|
+
* Fix return value from `with_progress{}` to equal `with_progress.each{}` [@toy](https://github.com/toy)
|
62
|
+
* Fix wrong variable name in `WithProgress#respond_to?` [@toy](https://github.com/toy)
|
63
|
+
* Fix using wrong constant `TempFile` instead of `Tempfile` [@toy](https://github.com/toy)
|
64
|
+
* Remove methods `eta` and `elapsed` created for mocking eta [@toy](https://github.com/toy)
|
65
|
+
* Rename `set_terminal_title` to `terminal_title` [@toy](https://github.com/toy)
|
66
|
+
|
67
|
+
## v3.0.2 (2014-12-19)
|
68
|
+
|
69
|
+
* Restore updating eta when there is no progress [@toy](https://github.com/toy)
|
70
|
+
|
71
|
+
## v3.0.1 (2014-08-18)
|
72
|
+
|
73
|
+
* Step once when running without block [@toy](https://github.com/toy)
|
74
|
+
* Fix working with `in_threads` by removing `WithProgress` inheritance of `Delegator` [@toy](https://github.com/toy)
|
75
|
+
|
76
|
+
## v3.0.0 (2013-08-20)
|
77
|
+
|
78
|
+
* Befriend with [`in_threads`](https://rubygems.org/gems/in_threads) gem [@toy](https://github.com/toy)
|
79
|
+
* Warn and use `to_a` on `IO` and `String` related objects before running progress, for other objects use for length in order: `size`, `length`, `count` [@toy](https://github.com/toy)
|
80
|
+
* Make `WithProgress` inherit `Delegator` [@toy](https://github.com/toy)
|
81
|
+
* Show elapsed time on finish [@toy](https://github.com/toy)
|
82
|
+
* Cleanup/rewrite, extract `Eta` and `Beeper` [@toy](https://github.com/toy)
|
83
|
+
* Conditionally require active_record support instead of conditionally creating module [@toy](https://github.com/toy)
|
84
|
+
* Don't kill dead thread for eta output without progress [@toy](https://github.com/toy)
|
85
|
+
* Don't show eta until at least one second passed [@toy](https://github.com/toy)
|
86
|
+
|
87
|
+
## v2.4.0 (2012-01-03)
|
88
|
+
|
89
|
+
* Add `Progress.running?` for checking if progress is running [@toy](https://github.com/toy)
|
90
|
+
|
91
|
+
## v2.3.0 (2011-12-25)
|
92
|
+
|
93
|
+
* Better handle edge cases of eta output without progress [@toy](https://github.com/toy)
|
94
|
+
* Call each only once for enumerable that can not be reused [@toy](https://github.com/toy)
|
95
|
+
* Allow to set length directly when calling `with_progress` [@toy](https://github.com/toy)
|
96
|
+
|
97
|
+
## v2.2.0 (2011-12-05)
|
98
|
+
|
99
|
+
* Make `with_progress.with_progress` create new instance instead of changing current, added enumerable and title attribute readers [@toy](https://github.com/toy)
|
100
|
+
|
101
|
+
## v2.1.1 (2011-12-04)
|
102
|
+
|
103
|
+
* Fix `with_progress.with_progress` with block not calling each [@toy](https://github.com/toy)
|
104
|
+
|
105
|
+
## v2.1.0 (2011-11-29)
|
106
|
+
|
107
|
+
* Change title when overriding progress with another call to `with_progress` [@toy](https://github.com/toy)
|
108
|
+
* Allow to directly specify length when initialising `WithProgress` [@toy](https://github.com/toy)
|
109
|
+
|
110
|
+
## v2.0.0 (2011-11-28)
|
111
|
+
|
112
|
+
* Show eta every second instead of every three when there is no progress [@toy](https://github.com/toy)
|
113
|
+
* Cache calculated length [@toy](https://github.com/toy)
|
114
|
+
* Use count method of enumerable if available to determine total for progress [@toy](https://github.com/toy)
|
115
|
+
* Call `each` with progress when `with_progress` is called with block [@toy](https://github.com/toy)
|
116
|
+
* Stop thread triggering eta update [@toy](https://github.com/toy)
|
117
|
+
* Rework `WithProgress` [@toy](https://github.com/toy)
|
118
|
+
* Remove `each_with_progress` and `each_with_index_and_progress` [@toy](https://github.com/toy)
|
119
|
+
|
120
|
+
## v1.2.1 (2011-10-18)
|
121
|
+
|
122
|
+
* Add missing `require 'thread'` [@toy](https://github.com/toy)
|
123
|
+
|
124
|
+
## v1.2.0 (2011-10-18)
|
125
|
+
|
126
|
+
* Updated eta every 3 seconds if nothing is happening [@toy](https://github.com/toy)
|
127
|
+
|
128
|
+
## v1.1.3 (2011-01-15)
|
129
|
+
|
130
|
+
* Fix `io` method, so `$stderr` can be silenced using `reopen` [@toy](https://github.com/toy)
|
131
|
+
* Remove `require 'rubygems'` [@toy](https://github.com/toy)
|
132
|
+
|
133
|
+
## v1.1.2.1 (2010-12-15)
|
134
|
+
|
135
|
+
* Internal gem changes [@toy](https://github.com/toy)
|
136
|
+
|
137
|
+
## v1.1.2 (2010-12-09)
|
138
|
+
|
139
|
+
* Use control character to clear line to end [@toy](https://github.com/toy)
|
140
|
+
|
141
|
+
## v1.1.1 (2010-12-07)
|
142
|
+
|
143
|
+
* Fix in notes handling [@toy](https://github.com/toy)
|
144
|
+
|
145
|
+
## v1.1.0 (2010-12-07)
|
146
|
+
|
147
|
+
* Add note for step [@toy](https://github.com/toy)
|
148
|
+
|
149
|
+
## v1.0.1 (2010-11-14)
|
150
|
+
|
151
|
+
* Fix progress by using `step` with block everywhere [@toy](https://github.com/toy)
|
152
|
+
* Separate `step` arguments to numerator and denominator [@toy](https://github.com/toy)
|
153
|
+
|
154
|
+
## v1.0.0 (2010-11-14)
|
155
|
+
|
156
|
+
* Show progress in terminal title [@toy](https://github.com/toy)
|
157
|
+
* Add eta [@toy](https://github.com/toy)
|
158
|
+
* Fix `step` by implementing through `set` and fix `set` return value [@toy](https://github.com/toy)
|
159
|
+
|
160
|
+
## v0.4.1 (2010-11-13)
|
161
|
+
|
162
|
+
* Fix active record batch extension inclusion [@toy](https://github.com/toy)
|
163
|
+
|
164
|
+
## v0.4.0 (2010-11-13)
|
165
|
+
|
166
|
+
* Add support for active record batch progress [@toy](https://github.com/toy)
|
167
|
+
* Fix `each_with_index_and_progress` requiring title [@toy](https://github.com/toy)
|
168
|
+
|
169
|
+
## v0.3.0 (2010-11-13)
|
170
|
+
|
171
|
+
* Allow progress without title [@toy](https://github.com/toy)
|
172
|
+
|
173
|
+
## v0.2.2 (2010-01-20)
|
174
|
+
|
175
|
+
* Fix bug in i18n gem [@toy](https://github.com/toy)
|
176
|
+
|
177
|
+
## v0.2.1 (2010-01-16)
|
178
|
+
|
179
|
+
* Ensure outputting final 100% of outer progress [@toy](https://github.com/toy)
|
180
|
+
|
181
|
+
## v0.2.0 (2009-12-30)
|
182
|
+
|
183
|
+
* Limit frequency of progress output [@toy](https://github.com/toy)
|
184
|
+
|
185
|
+
## v0.1.2 (2009-12-29)
|
186
|
+
|
187
|
+
* Internal gem changes [@toy](https://github.com/toy)
|
188
|
+
|
189
|
+
## v0.1.1.3 (2009-09-28)
|
190
|
+
|
191
|
+
* Remove debugging character from output [@toy](https://github.com/toy)
|
192
|
+
|
193
|
+
## v0.1.1.2 (2009-09-28)
|
194
|
+
|
195
|
+
* Fix highlighting [@toy](https://github.com/toy)
|
196
|
+
|
197
|
+
## v0.1.1.0 (2009-09-21)
|
198
|
+
|
199
|
+
* Allow `Progress(…)` instead `Progress.start(…)` [@toy](https://github.com/toy)
|
200
|
+
* Allow `step` to accept block for valid counting of custom progress [@toy](https://github.com/toy)
|
201
|
+
* Kill progress on cycle break [@toy](https://github.com/toy)
|
202
|
+
|
203
|
+
## v0.1.0.3 (2009-09-21)
|
204
|
+
|
205
|
+
* Internal gem changes [@toy](https://github.com/toy)
|
206
|
+
|
207
|
+
## v0.1.0.2 (2009-08-19)
|
208
|
+
|
209
|
+
* Don't raise error on extra `Progress.stop` [@toy](https://github.com/toy)
|
210
|
+
|
211
|
+
## v0.1.0.1 (2009-08-19)
|
212
|
+
|
213
|
+
* Fix output by verifying and converting progress to float [@toy](https://github.com/toy)
|
214
|
+
|
215
|
+
## v0.1.0.0 (2009-08-19)
|
216
|
+
|
217
|
+
* Inner progress increases outer progress, ability to set progress using `set` alongside stepping using `step` [@toy](https://github.com/toy)
|
218
|
+
|
219
|
+
## v0.0.9.3 (2009-08-06)
|
220
|
+
|
221
|
+
* Use space instead of `'>'` for padding [@toy](https://github.com/toy)
|
222
|
+
|
223
|
+
## v0.0.9.2 (2009-07-28)
|
224
|
+
|
225
|
+
* Force behaving as with tty by setting `PROGRESS_TTY` environment variable [@toy](https://github.com/toy)
|
226
|
+
|
227
|
+
## v0.0.9.1 (2009-07-28)
|
228
|
+
|
229
|
+
* Separate handling of staying on same line and colourising output [@toy](https://github.com/toy)
|
230
|
+
|
231
|
+
## v0.0.9.0 (2009-07-20)
|
232
|
+
|
233
|
+
* Add `Enumerable#with_progress` on which any enumerable method can be called [@toy](https://github.com/toy)
|
234
|
+
|
235
|
+
## v0.0.8.1 (2009-05-02)
|
236
|
+
|
237
|
+
* Return to line start after printing message instead of before [@toy](https://github.com/toy)
|
238
|
+
|
239
|
+
## v0.0.8 (2009-04-27)
|
240
|
+
|
241
|
+
* No colours and don't stay on same line when not on tty or explicitly using `:lines => true` option [@toy](https://github.com/toy)
|
242
|
+
|
243
|
+
## v0.0.7.1 (2009-04-24)
|
244
|
+
|
245
|
+
* Internal gem changes [@toy](https://github.com/toy)
|
246
|
+
|
247
|
+
## v0.0.7 (2009-03-24)
|
248
|
+
|
249
|
+
* Internal gem changes [@toy](https://github.com/toy)
|
250
|
+
|
251
|
+
## v0.0.6 (2009-02-19)
|
252
|
+
|
253
|
+
* Output to stderr [@toy](https://github.com/toy)
|
254
|
+
|
255
|
+
## v0.0.5 (2008-11-07)
|
256
|
+
|
257
|
+
* Return result of enumerable method [@toy](https://github.com/toy)
|
258
|
+
|
259
|
+
## v0.0.4 (2008-11-06)
|
260
|
+
|
261
|
+
* Allow to change step size [@toy](https://github.com/toy)
|
262
|
+
|
263
|
+
## v0.0.3 (2008-11-01)
|
264
|
+
|
265
|
+
* Output final newline after finishing progress [@toy](https://github.com/toy)
|
266
|
+
|
267
|
+
## v0.0.2 (2008-10-31)
|
268
|
+
|
269
|
+
* Allow enclosed progress [@toy](https://github.com/toy)
|
270
|
+
|
271
|
+
## v0.0.1 (2008-08-10)
|
272
|
+
|
273
|
+
* Initial [@toy](https://github.com/toy)
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[](https://rubygems.org/gems/progress)
|
2
2
|
[](https://travis-ci.org/toy/progress)
|
3
|
-
[](https://codeclimate.com/github/toy/progress)
|
4
|
+
[](https://depfu.com/github/toy/progress)
|
5
5
|
[](https://inch-ci.org/github/toy/progress)
|
6
6
|
|
7
7
|
# progress
|
@@ -14,127 +14,153 @@ Show progress during console script run.
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
```ruby
|
18
|
+
1000.times_with_progress('Counting to 1000') do |i|
|
19
|
+
# do something with i
|
20
|
+
end
|
21
|
+
```
|
20
22
|
|
21
23
|
or without title:
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
1000.times_with_progress do |i|
|
27
|
+
# do something with i
|
28
|
+
end
|
29
|
+
```
|
26
30
|
|
27
31
|
With array:
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
```ruby
|
34
|
+
[1, 2, 3].with_progress('1…2…3').each do |i|
|
35
|
+
# still counting
|
36
|
+
end
|
37
|
+
```
|
32
38
|
|
33
39
|
`.each` is optional:
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
```ruby
|
42
|
+
[1, 2, 3].with_progress('1…2…3') do |i|
|
43
|
+
# =||=
|
44
|
+
end
|
45
|
+
```
|
38
46
|
|
39
47
|
Nested progress
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
49
|
+
```ruby
|
50
|
+
(1..10).with_progress('Outer').map do |a|
|
51
|
+
(1..10).with_progress('Middle').map do |b|
|
52
|
+
(1..10).with_progress('Inner').map do |c|
|
53
|
+
# do something with a, b and c
|
47
54
|
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
48
58
|
|
49
59
|
You can also show note:
|
50
60
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
61
|
+
```ruby
|
62
|
+
[1, 2, 3].with_progress do |i|
|
63
|
+
Progress.note = i
|
64
|
+
sleep 5
|
65
|
+
end
|
66
|
+
```
|
55
67
|
|
56
68
|
You can use any enumerable method:
|
57
69
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
70
|
+
```ruby
|
71
|
+
[1, 2, 3].with_progress.map{ |i| 'do stuff' }
|
72
|
+
[1, 2, 3].with_progress.each_cons(3){ |i| 'do stuff' }
|
73
|
+
[1, 2, 3].with_progress.each_slice(2){ |i| 'do stuff' }
|
74
|
+
# …
|
75
|
+
```
|
62
76
|
|
63
77
|
Any enumerable will work:
|
64
78
|
|
65
|
-
|
66
|
-
|
67
|
-
|
79
|
+
```ruby
|
80
|
+
(1..100).with_progress('Wait') do |i|
|
81
|
+
# ranges are good
|
82
|
+
end
|
68
83
|
|
69
|
-
|
70
|
-
|
71
|
-
|
84
|
+
Dir.new('.').with_progress do |path|
|
85
|
+
# check path
|
86
|
+
end
|
87
|
+
```
|
72
88
|
|
73
89
|
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.
|
74
90
|
|
75
91
|
Use simple blocks:
|
76
92
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
93
|
+
```ruby
|
94
|
+
symbols = []
|
95
|
+
Progress.start('Input 100 symbols', 100) do
|
96
|
+
while symbols.length < 100
|
97
|
+
input = gets.scan(/\S/)
|
98
|
+
symbols += input
|
99
|
+
Progress.step input.length
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
85
103
|
|
86
104
|
or just
|
87
105
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
106
|
+
```ruby
|
107
|
+
symbols = []
|
108
|
+
Progress('Input 100 symbols', 100) do
|
109
|
+
while symbols.length < 100
|
110
|
+
input = gets.scan(/\S/)
|
111
|
+
symbols += input
|
112
|
+
Progress.step input.length
|
113
|
+
end
|
114
|
+
end
|
115
|
+
```
|
96
116
|
|
97
117
|
NOTE: you will get WRONG progress if you use something like this:
|
98
118
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
119
|
+
```ruby
|
120
|
+
10.times_with_progress('A') do |time|
|
121
|
+
10.times_with_progress('B') do
|
122
|
+
# code
|
123
|
+
end
|
124
|
+
10.times_with_progress('C') do
|
125
|
+
# code
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
107
129
|
|
108
130
|
But you can use this:
|
109
131
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
132
|
+
```ruby
|
133
|
+
10.times_with_progress('A') do |time|
|
134
|
+
Progress.step 5 do
|
135
|
+
10.times_with_progress('B') do
|
136
|
+
# code
|
137
|
+
end
|
138
|
+
end
|
139
|
+
Progress.step 5 do
|
140
|
+
10.times_with_progress('C') do
|
141
|
+
# code
|
121
142
|
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
```
|
122
146
|
|
123
147
|
Or if you know that B runs 9 times faster than C:
|
124
148
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
149
|
+
```ruby
|
150
|
+
10.times_with_progress('A') do |time|
|
151
|
+
Progress.step 1 do
|
152
|
+
10.times_with_progress('B') do
|
153
|
+
# code
|
154
|
+
end
|
155
|
+
end
|
156
|
+
Progress.step 9 do
|
157
|
+
10.times_with_progress('C') do
|
158
|
+
# code
|
136
159
|
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
```
|
137
163
|
|
138
164
|
## Copyright
|
139
165
|
|
140
|
-
Copyright (c)
|
166
|
+
Copyright (c) 2008-2021 Ivan Kuchin. See LICENSE.txt for details.
|