ruby-progressbar 1.5.1 → 1.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 +4 -4
- data/README.md +19 -1
- data/lib/ruby-progressbar/base.rb +3 -1
- data/lib/ruby-progressbar/components/progressable.rb +10 -3
- data/lib/ruby-progressbar/format/molecule.rb +2 -0
- data/lib/ruby-progressbar/formatter.rb +8 -0
- data/lib/ruby-progressbar/version.rb +1 -1
- data/spec/lib/ruby-progressbar/base_spec.rb +95 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f5b88d860cde93acea2fb44eaa5586d877e76d
|
4
|
+
data.tar.gz: 8c9611657c7def30f8188d4aaaca150dd30e34b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6b0ae26cfb96b3e9a2f5d3f691137a115ad44c1c88b30e578e1aecce96c7b2b268ddf957b16292aba43ae77d5b07ffb28df613e52a327e28d2388ed7e6b836d
|
7
|
+
data.tar.gz: 5e65be1a60e11c1e23b39f44532cbe39df09364316fd73122e15458949e3a6643732e2c9c3ed9976e1de4f7bbcf71268fe27b821bca34cb40e18d0e0866bdad8
|
data/README.md
CHANGED
@@ -132,7 +132,23 @@ The bar can be stopped in four ways:
|
|
132
132
|
|
133
133
|
* See `#finish` above.
|
134
134
|
|
135
|
-
|
135
|
+
By default, the bar will be finished automatically if the current value ever
|
136
|
+
becomes equal to the total. If you do not want the bar to autofinish, pass
|
137
|
+
`:autofinish => false` when creating your bar.
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
progressbar = ProgressBar.create(:starting_at => 9, :total => 10)
|
141
|
+
progressbar.increment
|
142
|
+
|
143
|
+
progressbar.finished? # => true
|
144
|
+
```
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
progressbar = ProgressBar.create(:starting_at => 9, :total => 10, :autofinish => false)
|
148
|
+
progressbar.increment
|
149
|
+
|
150
|
+
progressbar.finished? # => false
|
151
|
+
```
|
136
152
|
|
137
153
|
### Refreshing
|
138
154
|
|
@@ -210,6 +226,8 @@ The flags you can use in the format string are as follows:
|
|
210
226
|
* `%f`: Force estimated time to be displayed even if it exceeds `99:00:00`
|
211
227
|
* `%p`: Percentage complete represented as a whole number (eg: `82`)
|
212
228
|
* `%P`: Percentage complete represented as a decimal number (eg: `82.33`)
|
229
|
+
* `%j`: Percentage complete right-justified to 3 places (eg: ` 82`)
|
230
|
+
* `%J`: Percentage complete right-justified to 6 places (eg: ` 82.33`)
|
213
231
|
* `%c`: Number of items currently completed
|
214
232
|
* `%C`: Total number of items to be completed
|
215
233
|
* `%B`: The full progress bar including 'incomplete' space (eg: `========== `)
|
@@ -12,17 +12,20 @@ class ProgressBar
|
|
12
12
|
attr_accessor :starting_position
|
13
13
|
attr_accessor :running_average
|
14
14
|
attr_accessor :smoothing
|
15
|
+
attr_accessor :autofinish
|
16
|
+
attr_accessor :finished
|
15
17
|
|
16
18
|
def initialize(options = {})
|
17
19
|
self.total = options.fetch(:total, DEFAULT_TOTAL)
|
18
20
|
self.smoothing = options[:smoothing] || DEFAULT_SMOOTHING
|
21
|
+
self.autofinish = options.fetch(:autofinish, true)
|
19
22
|
|
20
23
|
start :at => DEFAULT_BEGINNING_POSITION
|
21
24
|
end
|
22
25
|
|
23
26
|
def start(options = {})
|
27
|
+
self.finished = false
|
24
28
|
self.running_average = 0
|
25
|
-
|
26
29
|
self.progress = \
|
27
30
|
self.starting_position = options[:at] || self.progress
|
28
31
|
end
|
@@ -32,7 +35,7 @@ class ProgressBar
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def finished?
|
35
|
-
|
38
|
+
finished || (autofinish && progress == total)
|
36
39
|
end
|
37
40
|
|
38
41
|
def increment
|
@@ -65,7 +68,8 @@ class ProgressBar
|
|
65
68
|
end
|
66
69
|
|
67
70
|
def finish
|
68
|
-
self.
|
71
|
+
self.finished = true
|
72
|
+
self.progress = total
|
69
73
|
end
|
70
74
|
|
71
75
|
def percentage_completed
|
@@ -81,6 +85,9 @@ class ProgressBar
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def percentage_completed_with_precision
|
88
|
+
return 100.0 if total == 0
|
89
|
+
return 0.0 if total.nil?
|
90
|
+
|
84
91
|
format('%5.2f', (progress.to_f * 100.0 / total * 100.0).floor / 100.0)
|
85
92
|
end
|
86
93
|
|
@@ -8,6 +8,8 @@ class ProgressBar
|
|
8
8
|
:C => :total,
|
9
9
|
:p => :percentage,
|
10
10
|
:P => :percentage_with_precision,
|
11
|
+
:j => :justified_percentage,
|
12
|
+
:J => :justified_percentage_with_precision,
|
11
13
|
:a => :elapsed_time,
|
12
14
|
:e => :estimated_time_with_unknown_oob,
|
13
15
|
:E => :estimated_time_with_friendly_oob,
|
@@ -45,10 +45,18 @@ class ProgressBar
|
|
45
45
|
@bar.percentage_completed
|
46
46
|
end
|
47
47
|
|
48
|
+
def justified_percentage
|
49
|
+
@bar.percentage_completed.to_s.rjust(3)
|
50
|
+
end
|
51
|
+
|
48
52
|
def percentage_with_precision
|
49
53
|
@bar.percentage_completed_with_precision
|
50
54
|
end
|
51
55
|
|
56
|
+
def justified_percentage_with_precision
|
57
|
+
@bar.percentage_completed_with_precision.to_s.rjust(6)
|
58
|
+
end
|
59
|
+
|
52
60
|
def elapsed_time
|
53
61
|
@elapsed_time
|
54
62
|
end
|
@@ -294,6 +294,31 @@ describe ProgressBar::Base do
|
|
294
294
|
non_tty_output.rewind
|
295
295
|
expect(non_tty_output.read).to eql "\n\nProgress: |====\n"
|
296
296
|
end
|
297
|
+
|
298
|
+
it 'ignores changes to the title due to the fact that the bar length cannot change' do
|
299
|
+
progressbar = ProgressBar::Base.new(:output => non_tty_output, :length => 20, :starting_at => 0, :total => 6, :throttle_rate => 0.0)
|
300
|
+
|
301
|
+
3.times { progressbar.increment }
|
302
|
+
|
303
|
+
progressbar.title = "Testing"
|
304
|
+
progressbar.stop
|
305
|
+
|
306
|
+
non_tty_output.rewind
|
307
|
+
|
308
|
+
expect(non_tty_output.read).to eql "\n\nProgress: |====\n"
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'allows the title to be customized when the bar is created' do
|
312
|
+
progressbar = ProgressBar::Base.new(:output => non_tty_output, :title => 'Custom', :length => 20, :starting_at => 0, :total => 6, :throttle_rate => 0.0)
|
313
|
+
|
314
|
+
3.times { progressbar.increment }
|
315
|
+
|
316
|
+
progressbar.stop
|
317
|
+
|
318
|
+
non_tty_output.rewind
|
319
|
+
|
320
|
+
expect(non_tty_output.read).to eql "\n\nCustom: |=====\n"
|
321
|
+
end
|
297
322
|
end
|
298
323
|
end
|
299
324
|
|
@@ -321,6 +346,50 @@ describe ProgressBar::Base do
|
|
321
346
|
end
|
322
347
|
end
|
323
348
|
|
349
|
+
context 'when a bar with autofinish=false is about to be completed' do
|
350
|
+
let(:progressbar) { ProgressBar::Base.new(:autofinish => false, :starting_at => 5, :total => 6, :output => output, :length => 20) }
|
351
|
+
|
352
|
+
context 'and it is incremented' do
|
353
|
+
before { progressbar.increment }
|
354
|
+
|
355
|
+
it 'does not automatically finish' do
|
356
|
+
expect(progressbar).not_to be_finished
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'does not prints a new line' do
|
360
|
+
output.rewind
|
361
|
+
|
362
|
+
expect(output.read.end_with?("\n")).to eql false
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'allows reset' do
|
366
|
+
progressbar.finish
|
367
|
+
expect(progressbar).to be_finished
|
368
|
+
|
369
|
+
progressbar.reset
|
370
|
+
|
371
|
+
expect(progressbar).not_to be_finished
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'does prints a new line when manually finished' do
|
375
|
+
progressbar.finish
|
376
|
+
expect(progressbar).to be_finished
|
377
|
+
|
378
|
+
output.rewind
|
379
|
+
|
380
|
+
expect(output.read.end_with?("\n")).to eql true
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'does not continue to print bars if finish is subsequently called' do
|
384
|
+
progressbar.finish
|
385
|
+
|
386
|
+
output.rewind
|
387
|
+
|
388
|
+
expect(output.read).to end_with " \rProgress: |====== |\rProgress: |========|\n"
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
324
393
|
context 'when a bar has an unknown amount to completion' do
|
325
394
|
let(:progressbar) { ProgressBar::Base.new(:total => nil, :output => output, :length => 80, :unknown_progress_animation_steps => ['=--', '-=-', '--=']) }
|
326
395
|
|
@@ -700,6 +769,20 @@ describe ProgressBar::Base do
|
|
700
769
|
expect(progressbar.to_s('%w%i')).to match /^= 5 =\s{95}\z/
|
701
770
|
end
|
702
771
|
|
772
|
+
it 'can display a percentage, even if the total is unknown' do
|
773
|
+
progressbar = ProgressBar::Base.new(:output => output, :length => 100, :total => nil, :starting_at => 0)
|
774
|
+
|
775
|
+
expect(progressbar.to_s('%p')).to match /\A0\z/
|
776
|
+
expect(progressbar.to_s('%P')).to match /\A0\.0\z/
|
777
|
+
end
|
778
|
+
|
779
|
+
it 'can display a percentage, even if the total is zero' do
|
780
|
+
progressbar = ProgressBar::Base.new(:output => output, :length => 100, :total => 0, :starting_at => 0)
|
781
|
+
|
782
|
+
expect(progressbar.to_s('%p')).to match /\A100\z/
|
783
|
+
expect(progressbar.to_s('%P')).to match /\A100\.0\z/
|
784
|
+
end
|
785
|
+
|
703
786
|
it 'displays the current capacity when passed the "%c" format flag' do
|
704
787
|
progressbar = ProgressBar::Base.new(:output => output, :starting_at => 0)
|
705
788
|
|
@@ -722,12 +805,24 @@ describe ProgressBar::Base do
|
|
722
805
|
expect(progressbar.to_s('%p')).to match /^16\z/
|
723
806
|
end
|
724
807
|
|
808
|
+
it 'displays the justified percentage complete when passed the "%j" format flag' do
|
809
|
+
progressbar = ProgressBar::Base.new(:starting_at => 33, :total => 200)
|
810
|
+
|
811
|
+
expect(progressbar.to_s('%j')).to match /^ 16\z/
|
812
|
+
end
|
813
|
+
|
725
814
|
it 'displays the percentage complete when passed the "%P" format flag' do
|
726
815
|
progressbar = ProgressBar::Base.new(:starting_at => 33, :total => 200)
|
727
816
|
|
728
817
|
expect(progressbar.to_s('%P')).to match /^16.50\z/
|
729
818
|
end
|
730
819
|
|
820
|
+
it 'displays the justified percentage complete when passed the "%J" format flag' do
|
821
|
+
progressbar = ProgressBar::Base.new(:starting_at => 33, :total => 200)
|
822
|
+
|
823
|
+
expect(progressbar.to_s('%J')).to match /^ 16.50\z/
|
824
|
+
end
|
825
|
+
|
731
826
|
it 'displays only up to 2 decimal places when using the "%P" flag' do
|
732
827
|
progressbar = ProgressBar::Base.new(:starting_at => 66, :total => 99)
|
733
828
|
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thekompanee
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -162,3 +162,4 @@ test_files:
|
|
162
162
|
- spec/lib/ruby-progressbar/running_average_calculator_spec.rb
|
163
163
|
- spec/lib/ruby-progressbar/time_spec.rb
|
164
164
|
- spec/support/time.rb
|
165
|
+
has_rdoc:
|