ruby-progressbar 1.3.2 → 1.4.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.
- data/README.md +2 -1
- data/lib/ruby-progressbar/base.rb +18 -9
- data/lib/ruby-progressbar/components/estimated_timer.rb +2 -2
- data/lib/ruby-progressbar/components/progressable.rb +12 -2
- data/lib/ruby-progressbar/components/timer.rb +1 -2
- data/lib/ruby-progressbar/errors/invalid_progress_error.rb +4 -0
- data/lib/ruby-progressbar/version.rb +1 -1
- data/spec/lib/ruby-progressbar/base_spec.rb +11 -15
- data/spec/lib/ruby-progressbar/components/bar_spec.rb +1 -1
- data/spec/lib/ruby-progressbar/components/estimated_timer_spec.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -19,6 +19,7 @@ Supported Rubies
|
|
19
19
|
It's Better Than The Other 186,312 Progress Bar Libraries Because...
|
20
20
|
--------------------------------
|
21
21
|
* Full test suite [](http://travis-ci.org/jfelchner/ruby-progressbar)
|
22
|
+
* _**ZERO**_ dependencies
|
22
23
|
* Used by tons of other open source projects (which means we find out about bugs quickly)
|
23
24
|
* It's pretty [freakin' sweet](https://www.youtube.com/watch?v=On3IoVhf_GM)
|
24
25
|
* We have a road map of new features to make it even better
|
@@ -393,5 +394,5 @@ And a special thanks to [Satoru Takabayashi](http://namazu.org/~satoru/) who was
|
|
393
394
|
License
|
394
395
|
--------------------------------
|
395
396
|
|
396
|
-
ruby-progressbar 1.0 is Copyright © 2011-
|
397
|
+
ruby-progressbar 1.0 is Copyright © 2011-2014 The Kompanee. It is free software, and may be redistributed under the terms specified in the LICENSE file.
|
397
398
|
ruby-progressbar 0.9.0 is Copyright © 2008 [Satoru Takabayashi](http://namazu.org/~satoru/)
|
@@ -27,7 +27,7 @@ class ProgressBar
|
|
27
27
|
|
28
28
|
with_update do
|
29
29
|
with_progressables(:start, options)
|
30
|
-
|
30
|
+
with_timers(:start)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,26 +35,26 @@ class ProgressBar
|
|
35
35
|
# Updating The Bar's Progress
|
36
36
|
#
|
37
37
|
def decrement
|
38
|
-
|
38
|
+
update_progress(:decrement)
|
39
39
|
end
|
40
40
|
|
41
41
|
def increment
|
42
|
-
|
42
|
+
update_progress(:increment)
|
43
43
|
end
|
44
44
|
|
45
45
|
def progress=(new_progress)
|
46
|
-
|
46
|
+
update_progress(:progress=, new_progress)
|
47
47
|
end
|
48
48
|
|
49
49
|
def total=(new_total)
|
50
|
-
|
50
|
+
update_progress(:total=, new_total)
|
51
51
|
end
|
52
52
|
|
53
53
|
###
|
54
54
|
# Stopping The Bar
|
55
55
|
#
|
56
56
|
def finish
|
57
|
-
with_update { with_progressables(:finish) } unless finished?
|
57
|
+
with_update { with_progressables(:finish); with_timers(:stop) } unless finished?
|
58
58
|
end
|
59
59
|
|
60
60
|
def pause
|
@@ -83,7 +83,11 @@ class ProgressBar
|
|
83
83
|
alias :paused? :stopped?
|
84
84
|
|
85
85
|
def finished?
|
86
|
-
@
|
86
|
+
@estimated_time.finished? && @bar.finished?
|
87
|
+
end
|
88
|
+
|
89
|
+
def started?
|
90
|
+
@estimated_time.started? && @elapsed_time.started? && @bar.started?
|
87
91
|
end
|
88
92
|
|
89
93
|
###
|
@@ -158,14 +162,19 @@ class ProgressBar
|
|
158
162
|
@elapsed_time.send(*args)
|
159
163
|
end
|
160
164
|
|
165
|
+
def update_progress(*args)
|
166
|
+
with_update do
|
167
|
+
with_progressables(*args)
|
168
|
+
with_timers(:stop) if finished?
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
161
172
|
def with_update
|
162
173
|
yield
|
163
174
|
update
|
164
175
|
end
|
165
176
|
|
166
177
|
def update(options = {})
|
167
|
-
with_timers(:stop) if finished?
|
168
|
-
|
169
178
|
if length_changed?
|
170
179
|
clear
|
171
180
|
reset_length
|
@@ -32,9 +32,9 @@ class ProgressBar
|
|
32
32
|
|
33
33
|
private
|
34
34
|
def estimated_time
|
35
|
-
return '??:??:??' if progress_made.zero?
|
35
|
+
return '??:??:??' if progress_made.zero? || total.nil?
|
36
36
|
|
37
|
-
hours, minutes, seconds = divide_seconds(estimated_seconds_remaining)
|
37
|
+
hours, minutes, seconds = *divide_seconds(estimated_seconds_remaining)
|
38
38
|
|
39
39
|
if hours > 99 && @out_of_bounds_time_format
|
40
40
|
out_of_bounds_time
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ruby-progressbar/errors/invalid_progress_error'
|
2
|
+
|
1
3
|
class ProgressBar
|
2
4
|
module Components
|
3
5
|
module Progressable
|
@@ -29,11 +31,19 @@ class ProgressBar
|
|
29
31
|
!!self.starting_position
|
30
32
|
end
|
31
33
|
|
34
|
+
def finished?
|
35
|
+
self.progress == self.total
|
36
|
+
end
|
37
|
+
|
32
38
|
def increment
|
39
|
+
STDOUT.puts "WARNING: Your progress bar is currently at #{progress} out of #{total} and cannot be incremented. In v2.0.0 this will become a ProgressBar::InvalidProgressError." if progress == total
|
40
|
+
|
33
41
|
self.progress += 1 unless progress == total
|
34
42
|
end
|
35
43
|
|
36
44
|
def decrement
|
45
|
+
STDOUT.puts "WARNING: Your progress bar is currently at #{progress} out of #{total} and cannot be decremented. In v2.0.0 this will become a ProgressBar::InvalidProgressError." if progress == 0
|
46
|
+
|
37
47
|
self.progress -= 1 unless progress == 0
|
38
48
|
end
|
39
49
|
|
@@ -76,11 +86,11 @@ class ProgressBar
|
|
76
86
|
|
77
87
|
private
|
78
88
|
def validate_total(new_total)
|
79
|
-
(progress.nil? || new_total.nil? || new_total >= progress) || raise("You can't set the item's total value to be less than the current progress.")
|
89
|
+
(progress.nil? || new_total.nil? || new_total >= progress) || raise(ProgressBar::InvalidProgressError, "You can't set the item's total value to be less than the current progress.")
|
80
90
|
end
|
81
91
|
|
82
92
|
def validate_progress(new_progress)
|
83
|
-
(total.nil? || new_progress <= total) || raise("You can't set the item's current value to be greater than the total.")
|
93
|
+
(total.nil? || new_progress <= total) || raise(ProgressBar::InvalidProgressError, "You can't set the item's current value to be greater than the total.")
|
84
94
|
end
|
85
95
|
|
86
96
|
def progress_made
|
@@ -51,8 +51,7 @@ class ProgressBar
|
|
51
51
|
def elapsed_time
|
52
52
|
return '--:--:--' unless started?
|
53
53
|
|
54
|
-
hours, seconds = elapsed_whole_seconds
|
55
|
-
minutes, seconds = seconds.divmod(60)
|
54
|
+
hours, minutes, seconds = *divide_seconds(elapsed_whole_seconds)
|
56
55
|
|
57
56
|
sprintf TIME_FORMAT, hours, minutes, seconds
|
58
57
|
end
|
@@ -20,14 +20,12 @@ describe ProgressBar::Base do
|
|
20
20
|
it 'can properly handle outputting the bar when the length changes on the fly to less than the minimum width' do
|
21
21
|
progressbar = ProgressBar::Base.new(:output => output, :title => 'a' * 25, :format => '%t%B', :throttle_rate => 0.0)
|
22
22
|
|
23
|
-
|
24
|
-
allow(progressbar).to receive(:dynamic_width_stty).
|
23
|
+
allow(progressbar).to receive(:terminal_width).
|
25
24
|
and_return 30
|
26
25
|
|
27
26
|
progressbar.start
|
28
27
|
|
29
|
-
|
30
|
-
allow(progressbar).to receive(:dynamic_width_stty).
|
28
|
+
allow(progressbar).to receive(:terminal_width).
|
31
29
|
and_return 20
|
32
30
|
|
33
31
|
progressbar.increment
|
@@ -40,8 +38,7 @@ describe ProgressBar::Base do
|
|
40
38
|
it 'returns the proper string' do
|
41
39
|
progressbar = ProgressBar::Base.new(:output => output, :title => ('*' * 21), :starting_at => 5, :total => 10, :autostart => false)
|
42
40
|
|
43
|
-
|
44
|
-
allow(progressbar).to receive(:dynamic_width_stty).
|
41
|
+
allow(progressbar).to receive(:terminal_width).
|
45
42
|
and_return 20
|
46
43
|
|
47
44
|
progressbar.to_s('%t%w').should eql '*********************'
|
@@ -52,8 +49,7 @@ describe ProgressBar::Base do
|
|
52
49
|
it 'returns the proper string' do
|
53
50
|
progressbar = ProgressBar::Base.new(:output => output, :title => ('*' * 21), :autostart => false)
|
54
51
|
|
55
|
-
|
56
|
-
allow(progressbar).to receive(:dynamic_width_stty).
|
52
|
+
allow(progressbar).to receive(:terminal_width).
|
57
53
|
and_return 20
|
58
54
|
|
59
55
|
progressbar.to_s('%t%i').should eql '*********************'
|
@@ -62,8 +58,7 @@ describe ProgressBar::Base do
|
|
62
58
|
it 'returns the proper string' do
|
63
59
|
progressbar = ProgressBar::Base.new(:output => output, :title => ('*' * 21), :starting_at => 5, :total => 10, :autostart => false)
|
64
60
|
|
65
|
-
|
66
|
-
allow(progressbar).to receive(:dynamic_width_stty).
|
61
|
+
allow(progressbar).to receive(:terminal_width).
|
67
62
|
and_return 20
|
68
63
|
|
69
64
|
progressbar.to_s('%t%i').should eql '*********************'
|
@@ -74,8 +69,7 @@ describe ProgressBar::Base do
|
|
74
69
|
it 'returns the proper string' do
|
75
70
|
progressbar = ProgressBar::Base.new(:output => output, :title => ('*' * 19), :starting_at => 5, :total => 10, :autostart => false)
|
76
71
|
|
77
|
-
|
78
|
-
allow(progressbar).to receive(:dynamic_width_stty).
|
72
|
+
allow(progressbar).to receive(:terminal_width).
|
79
73
|
and_return 20
|
80
74
|
|
81
75
|
progressbar.to_s('%t%B').should eql '******************* '
|
@@ -84,8 +78,7 @@ describe ProgressBar::Base do
|
|
84
78
|
it 'returns the proper string' do
|
85
79
|
progressbar = ProgressBar::Base.new(:output => output, :title => ('*' * 19), :starting_at => 5, :total => 10, :autostart => false)
|
86
80
|
|
87
|
-
|
88
|
-
allow(progressbar).to receive(:dynamic_width_stty).
|
81
|
+
allow(progressbar).to receive(:terminal_width).
|
89
82
|
and_return 20
|
90
83
|
|
91
84
|
progressbar.to_s('%t%w%i').should eql '******************* '
|
@@ -346,7 +339,10 @@ describe ProgressBar::Base do
|
|
346
339
|
end
|
347
340
|
|
348
341
|
it 'displays the proper ETA' do
|
349
|
-
progressbar.
|
342
|
+
progressbar.increment
|
343
|
+
|
344
|
+
progressbar.to_s('%i%e').should eql '-=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=- ETA: ??:??:??'
|
345
|
+
progressbar.to_s('%i%E').should eql '-=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=- ETA: ??:??:??'
|
350
346
|
end
|
351
347
|
end
|
352
348
|
|
@@ -203,7 +203,7 @@ describe ProgressBar::Components::Bar do
|
|
203
203
|
describe '#new' do
|
204
204
|
it 'raises an error' do
|
205
205
|
@progressbar = ProgressBar::Components::Bar.new(:total => 10)
|
206
|
-
lambda { @progressbar.start :at => 11 }.should raise_error "You can't set the item's current value to be greater than the total."
|
206
|
+
lambda { @progressbar.start :at => 11 }.should raise_error(ProgressBar::InvalidProgressError, "You can't set the item's current value to be greater than the total.")
|
207
207
|
end
|
208
208
|
end
|
209
209
|
end
|
@@ -4,7 +4,7 @@ describe ProgressBar::Components::EstimatedTimer do
|
|
4
4
|
describe '#progress=' do
|
5
5
|
it 'raises an error when passed a number larger than the total' do
|
6
6
|
@estimated_time = ProgressBar::Components::EstimatedTimer.new(:total => 100)
|
7
|
-
lambda{ @estimated_time.progress = 101 }.should raise_error "You can't set the item's current value to be greater than the total."
|
7
|
+
lambda{ @estimated_time.progress = 101 }.should raise_error(ProgressBar::InvalidProgressError, "You can't set the item's current value to be greater than the total.")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-progressbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-12-
|
13
|
+
date: 2013-12-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/ruby-progressbar/components/throttle.rb
|
84
84
|
- lib/ruby-progressbar/components/timer.rb
|
85
85
|
- lib/ruby-progressbar/components.rb
|
86
|
+
- lib/ruby-progressbar/errors/invalid_progress_error.rb
|
86
87
|
- lib/ruby-progressbar/format/base.rb
|
87
88
|
- lib/ruby-progressbar/format/molecule.rb
|
88
89
|
- lib/ruby-progressbar/format.rb
|