ruby-progressbar 1.6.0 → 1.6.1
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 +1 -1
- data/Rakefile +2 -0
- data/lib/ruby-progressbar.rb +1 -1
- data/lib/ruby-progressbar/base.rb +5 -2
- data/lib/ruby-progressbar/components/elapsed_timer.rb +5 -0
- data/lib/ruby-progressbar/components/estimated_timer.rb +5 -1
- data/lib/ruby-progressbar/components/rate.rb +3 -1
- data/lib/ruby-progressbar/components/throttle.rb +3 -1
- data/lib/ruby-progressbar/formatter.rb +1 -0
- data/lib/ruby-progressbar/length_calculator.rb +2 -1
- data/lib/ruby-progressbar/version.rb +1 -1
- data/spec/lib/ruby-progressbar/base_spec.rb +68 -68
- data/spec/lib/ruby-progressbar/components/bar_spec.rb +1 -1
- data/spec/lib/ruby-progressbar/components/elapsed_timer_spec.rb +1 -1
- data/spec/lib/ruby-progressbar/components/estimated_timer_spec.rb +1 -1
- data/spec/lib/ruby-progressbar/components/progressable_spec.rb +1 -1
- data/spec/lib/ruby-progressbar/components/throttle_spec.rb +1 -1
- data/spec/lib/ruby-progressbar/running_average_calculator_spec.rb +1 -1
- data/spec/lib/ruby-progressbar/time_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- metadata +22 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ab0a31d7bb98cd80041a9c7a30d02d06f5ff2c0
|
4
|
+
data.tar.gz: cc94aa0ec99f5638339360ac366cf11e9bbc6b77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e2e0bbc3a033fcab712a3dc2b636018c3206e6bbd0ac5998d53a1719e195c3d8ee895dfb98c075b4f5fdd939cd862a26269cb0f01b3aa6b8f59cd1825a8eebc
|
7
|
+
data.tar.gz: cffef174c3686916351cf8482f61602574a0eaf566fcf5f8d4045ba1fad127181766006bd9c8fdf884a83a832f835257ba462e57670f2ecb3595e707801546f9
|
data/README.md
CHANGED
@@ -105,7 +105,7 @@ The following are the list of options you can use:
|
|
105
105
|
* `:remainder_mark` - _(Defaults to ` `)_ The mark which indicates the remaining amount of progress to be made.
|
106
106
|
* `:format` - _(Defaults to `%t: |%B|`)_ The format string which determines how the bar is displayed. See [**Formatting**](#formatting) below.
|
107
107
|
* `:length` - _(Defaults to full width if possible, otherwise `80`)_ The preferred width of the entire progress bar including any format options.
|
108
|
-
* `:output` - _(Defaults to `STDOUT`)_ All output will be sent to this object. Can be any object which responds to `.print`.
|
108
|
+
* `:output` - _(Defaults to `STDOUT`)_ All output will be sent to this object. Can be any object which responds to `.print` `.flush` `.tty?` `.puts`.
|
109
109
|
* `:smoothing` - _(Defaults to `0.1`)_ See [**Smoothing Out Estimated Time Jitters**](#smoothing-out-estimated-time-jitters) below.
|
110
110
|
* `:throttle_rate` - _(Defaults to `0.01`)_ See [**Throttling**](#throttling) below.
|
111
111
|
* `:unknown_progress_animation_steps` - _(Defaults to `['=---', '-=--', '--=-', '---=']`)_ See [**Unknown Progress**](#unknown-progress) The graphical elements used to cycle when progress is changed but the total amount of items being processed is unknown.
|
data/Rakefile
ADDED
data/lib/ruby-progressbar.rb
CHANGED
@@ -143,9 +143,12 @@ class ProgressBar
|
|
143
143
|
"#<ProgressBar:#{progress}/#{total || 'unknown'}>"
|
144
144
|
end
|
145
145
|
|
146
|
+
protected
|
147
|
+
|
148
|
+
attr_accessor :output,
|
149
|
+
:last_update_length
|
150
|
+
|
146
151
|
private
|
147
|
-
attr_accessor :output,
|
148
|
-
:last_update_length
|
149
152
|
|
150
153
|
def clear_string
|
151
154
|
"#{" " * length}"
|
@@ -7,6 +7,10 @@ class ProgressBar
|
|
7
7
|
VALID_OOB_TIME_FORMATS = [:unknown, :friendly, nil]
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
|
+
@out_of_bounds_time_format = nil
|
11
|
+
@starting_at = nil
|
12
|
+
@stopped_at = nil
|
13
|
+
|
10
14
|
super
|
11
15
|
end
|
12
16
|
|
@@ -66,7 +70,7 @@ class ProgressBar
|
|
66
70
|
end
|
67
71
|
|
68
72
|
class As
|
69
|
-
private
|
73
|
+
private(*instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ })
|
70
74
|
|
71
75
|
def initialize(subject, ancestor)
|
72
76
|
@subject = subject
|
@@ -8,6 +8,8 @@ class ProgressBar
|
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
self.rate_scale = options[:rate_scale]
|
11
|
+
@started_at = nil
|
12
|
+
@stopped_at = nil
|
11
13
|
|
12
14
|
super
|
13
15
|
end
|
@@ -49,7 +51,7 @@ class ProgressBar
|
|
49
51
|
end
|
50
52
|
|
51
53
|
class As
|
52
|
-
private
|
54
|
+
private(*instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ })
|
53
55
|
|
54
56
|
def initialize(subject, ancestor)
|
55
57
|
@subject = subject
|
@@ -4,7 +4,9 @@ class ProgressBar
|
|
4
4
|
include Timer
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
|
-
@period
|
7
|
+
@period = options.delete(:throttle_rate) { 0.01 } || 0.01
|
8
|
+
@started_at = nil
|
9
|
+
@stopped_at = nil
|
8
10
|
end
|
9
11
|
|
10
12
|
def choke(force = false, &block)
|
@@ -3,6 +3,7 @@ class ProgressBar
|
|
3
3
|
def initialize(options)
|
4
4
|
@length_override = ENV['RUBY_PROGRESS_BAR_LENGTH'] || options[:length]
|
5
5
|
@length_override = @length_override.to_i if @length_override
|
6
|
+
@current_length = nil
|
6
7
|
|
7
8
|
super()
|
8
9
|
end
|
@@ -39,7 +40,7 @@ class ProgressBar
|
|
39
40
|
require 'io/console'
|
40
41
|
|
41
42
|
def dynamic_width
|
42
|
-
|
43
|
+
_rows, columns = IO.console.winsize
|
43
44
|
columns
|
44
45
|
end
|
45
46
|
rescue LoadError
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'support/time'
|
3
3
|
require 'stringio'
|
4
4
|
|
@@ -32,7 +32,7 @@ describe ProgressBar::Base do
|
|
32
32
|
progressbar.increment
|
33
33
|
|
34
34
|
output.rewind
|
35
|
-
expect(output.read).to match
|
35
|
+
expect(output.read).to match(/\raaaaaaaaaaaaaaaaaaaaaaaaa \r\s+\raaaaaaaaaaaaaaaaaaaaaaaaa\r\z/)
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'and the bar length is calculated' do
|
@@ -186,7 +186,7 @@ describe ProgressBar::Base do
|
|
186
186
|
|
187
187
|
it 'completes the bar' do
|
188
188
|
output.rewind
|
189
|
-
expect(output.read).to match
|
189
|
+
expect(output.read).to match(/Progress: \|#{'=' * 68}\|\n/)
|
190
190
|
end
|
191
191
|
|
192
192
|
it 'shows the elapsed time instead of the estimated time since the bar is completed' do
|
@@ -427,7 +427,7 @@ describe ProgressBar::Base do
|
|
427
427
|
progressbar.progress_mark = 'x'
|
428
428
|
|
429
429
|
output.rewind
|
430
|
-
expect(output.read).to match
|
430
|
+
expect(output.read).to match(/\rProgress: \|xxxxxx#{' ' * 62}\|\r\z/)
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
@@ -436,7 +436,7 @@ describe ProgressBar::Base do
|
|
436
436
|
progressbar.remainder_mark = 'x'
|
437
437
|
|
438
438
|
output.rewind
|
439
|
-
expect(output.read).to match
|
439
|
+
expect(output.read).to match(/\rProgress: \|======#{'x' * 62}\|\r\z/)
|
440
440
|
end
|
441
441
|
end
|
442
442
|
|
@@ -445,7 +445,7 @@ describe ProgressBar::Base do
|
|
445
445
|
progressbar.title = 'Items'
|
446
446
|
|
447
447
|
output.rewind
|
448
|
-
expect(output.read).to match
|
448
|
+
expect(output.read).to match(/\rItems: \|=======#{' ' * 64}\|\r\z/)
|
449
449
|
end
|
450
450
|
end
|
451
451
|
|
@@ -454,7 +454,7 @@ describe ProgressBar::Base do
|
|
454
454
|
|
455
455
|
it 'resets the bar back to the starting value' do
|
456
456
|
output.rewind
|
457
|
-
expect(output.read).to match
|
457
|
+
expect(output.read).to match(/\rProgress: \|#{' ' * 68}\|\r\z/)
|
458
458
|
end
|
459
459
|
end
|
460
460
|
|
@@ -463,7 +463,7 @@ describe ProgressBar::Base do
|
|
463
463
|
|
464
464
|
it 'forcibly halts the bar wherever it is and cancels it' do
|
465
465
|
output.rewind
|
466
|
-
expect(output.read).to match
|
466
|
+
expect(output.read).to match(/\rProgress: \|======#{' ' * 62}\|\n\z/)
|
467
467
|
end
|
468
468
|
|
469
469
|
it 'does not output the bar multiple times if the bar is already stopped' do
|
@@ -498,7 +498,7 @@ describe ProgressBar::Base do
|
|
498
498
|
|
499
499
|
it 'resets the bar back to the starting value' do
|
500
500
|
output.rewind
|
501
|
-
expect(output.read).to match
|
501
|
+
expect(output.read).to match(/\rProgress: \|==========#{' ' * 90}\|\r\z/)
|
502
502
|
end
|
503
503
|
end
|
504
504
|
end
|
@@ -509,7 +509,7 @@ describe ProgressBar::Base do
|
|
509
509
|
progressbar.clear
|
510
510
|
|
511
511
|
output.rewind
|
512
|
-
expect(output.read).to match
|
512
|
+
expect(output.read).to match(/^#{progressbar.send(:clear_string)}/)
|
513
513
|
end
|
514
514
|
end
|
515
515
|
|
@@ -518,21 +518,21 @@ describe ProgressBar::Base do
|
|
518
518
|
progressbar.start
|
519
519
|
|
520
520
|
output.rewind
|
521
|
-
expect(output.read).to match
|
521
|
+
expect(output.read).to match(/^#{progressbar.send(:clear_string)}/)
|
522
522
|
end
|
523
523
|
|
524
524
|
it 'prints the bar for the first time' do
|
525
525
|
progressbar.start
|
526
526
|
|
527
527
|
output.rewind
|
528
|
-
expect(output.read).to match
|
528
|
+
expect(output.read).to match(/Progress: \| \|\r\z/)
|
529
529
|
end
|
530
530
|
|
531
531
|
it 'prints correctly if passed a position to start at' do
|
532
532
|
progressbar.start(:at => 20)
|
533
533
|
|
534
534
|
output.rewind
|
535
|
-
expect(output.read).to match
|
535
|
+
expect(output.read).to match(/Progress: \|============= \|\r\z/)
|
536
536
|
end
|
537
537
|
end
|
538
538
|
|
@@ -544,7 +544,7 @@ describe ProgressBar::Base do
|
|
544
544
|
|
545
545
|
it 'displays the bar with the correct formatting' do
|
546
546
|
output.rewind
|
547
|
-
expect(output.read).to match
|
547
|
+
expect(output.read).to match(/Progress: \|== \|\r\z/)
|
548
548
|
end
|
549
549
|
end
|
550
550
|
end
|
@@ -557,7 +557,7 @@ describe ProgressBar::Base do
|
|
557
557
|
before { progressbar.format }
|
558
558
|
|
559
559
|
it 'resets the format back to the default' do
|
560
|
-
expect(progressbar.to_s).to match
|
560
|
+
expect(progressbar.to_s).to match(/^Progress: \|\s+\|\z/)
|
561
561
|
end
|
562
562
|
end
|
563
563
|
|
@@ -565,7 +565,7 @@ describe ProgressBar::Base do
|
|
565
565
|
before { progressbar.format '%t' }
|
566
566
|
|
567
567
|
it 'sets it as the new format for the bar' do
|
568
|
-
expect(progressbar.to_s).to match
|
568
|
+
expect(progressbar.to_s).to match(/^Progress\z/)
|
569
569
|
end
|
570
570
|
end
|
571
571
|
end
|
@@ -576,7 +576,7 @@ describe ProgressBar::Base do
|
|
576
576
|
Timecop.freeze do
|
577
577
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 0)
|
578
578
|
|
579
|
-
expect(progressbar.to_s('%r')).to match
|
579
|
+
expect(progressbar.to_s('%r')).to match(/^0\z/)
|
580
580
|
end
|
581
581
|
end
|
582
582
|
end
|
@@ -587,7 +587,7 @@ describe ProgressBar::Base do
|
|
587
587
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20)
|
588
588
|
|
589
589
|
Timecop.travel(2) do
|
590
|
-
expect(progressbar.to_s('%r')).to match
|
590
|
+
expect(progressbar.to_s('%r')).to match(/^0\z/)
|
591
591
|
end
|
592
592
|
end
|
593
593
|
|
@@ -595,7 +595,7 @@ describe ProgressBar::Base do
|
|
595
595
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20)
|
596
596
|
|
597
597
|
Timecop.travel(2) do
|
598
|
-
expect(progressbar.to_s('%R')).to match
|
598
|
+
expect(progressbar.to_s('%R')).to match(/^0.00\z/)
|
599
599
|
end
|
600
600
|
end
|
601
601
|
|
@@ -606,7 +606,7 @@ describe ProgressBar::Base do
|
|
606
606
|
progressbar.progress += 20
|
607
607
|
|
608
608
|
Timecop.travel(2) do
|
609
|
-
expect(progressbar.to_s('%r')).to match
|
609
|
+
expect(progressbar.to_s('%r')).to match(/^10\z/)
|
610
610
|
end
|
611
611
|
end
|
612
612
|
end
|
@@ -618,7 +618,7 @@ describe ProgressBar::Base do
|
|
618
618
|
progressbar.progress += 13
|
619
619
|
|
620
620
|
Timecop.travel(2) do
|
621
|
-
expect(progressbar.to_s('%R')).to match
|
621
|
+
expect(progressbar.to_s('%R')).to match(/^6.50\z/)
|
622
622
|
end
|
623
623
|
end
|
624
624
|
end
|
@@ -630,7 +630,7 @@ describe ProgressBar::Base do
|
|
630
630
|
progressbar.progress += 20
|
631
631
|
|
632
632
|
Timecop.travel(2) do
|
633
|
-
expect(progressbar.to_s('%r')).to match
|
633
|
+
expect(progressbar.to_s('%r')).to match(/^10\z/)
|
634
634
|
end
|
635
635
|
end
|
636
636
|
end
|
@@ -642,7 +642,7 @@ describe ProgressBar::Base do
|
|
642
642
|
progressbar.progress += 10
|
643
643
|
|
644
644
|
Timecop.travel(6) do
|
645
|
-
expect(progressbar.to_s('%R')).to match
|
645
|
+
expect(progressbar.to_s('%R')).to match(/^1.67\z/)
|
646
646
|
end
|
647
647
|
end
|
648
648
|
end
|
@@ -653,7 +653,7 @@ describe ProgressBar::Base do
|
|
653
653
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20, :rate_scale => lambda { |rate| rate / 2 })
|
654
654
|
|
655
655
|
Timecop.travel(2) do
|
656
|
-
expect(progressbar.to_s('%r')).to match
|
656
|
+
expect(progressbar.to_s('%r')).to match(/^0\z/)
|
657
657
|
end
|
658
658
|
end
|
659
659
|
|
@@ -661,7 +661,7 @@ describe ProgressBar::Base do
|
|
661
661
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20, :rate_scale => lambda { |rate| rate / 2 })
|
662
662
|
|
663
663
|
Timecop.travel(2) do
|
664
|
-
expect(progressbar.to_s('%R')).to match
|
664
|
+
expect(progressbar.to_s('%R')).to match(/^0.00\z/)
|
665
665
|
end
|
666
666
|
end
|
667
667
|
|
@@ -672,7 +672,7 @@ describe ProgressBar::Base do
|
|
672
672
|
progressbar.progress += 20
|
673
673
|
|
674
674
|
Timecop.travel(2) do
|
675
|
-
expect(progressbar.to_s('%r')).to match
|
675
|
+
expect(progressbar.to_s('%r')).to match(/^5\z/)
|
676
676
|
end
|
677
677
|
end
|
678
678
|
end
|
@@ -684,7 +684,7 @@ describe ProgressBar::Base do
|
|
684
684
|
progressbar.progress += 13
|
685
685
|
|
686
686
|
Timecop.travel(2) do
|
687
|
-
expect(progressbar.to_s('%R')).to match
|
687
|
+
expect(progressbar.to_s('%R')).to match(/^3.25\z/)
|
688
688
|
end
|
689
689
|
end
|
690
690
|
end
|
@@ -696,7 +696,7 @@ describe ProgressBar::Base do
|
|
696
696
|
progressbar.progress += 20
|
697
697
|
|
698
698
|
Timecop.travel(2) do
|
699
|
-
expect(progressbar.to_s('%r')).to match
|
699
|
+
expect(progressbar.to_s('%r')).to match(/^5\z/)
|
700
700
|
end
|
701
701
|
end
|
702
702
|
end
|
@@ -708,7 +708,7 @@ describe ProgressBar::Base do
|
|
708
708
|
progressbar.progress += 10
|
709
709
|
|
710
710
|
Timecop.travel(6) do
|
711
|
-
expect(progressbar.to_s('%R')).to match
|
711
|
+
expect(progressbar.to_s('%R')).to match(/^0.83\z/)
|
712
712
|
end
|
713
713
|
end
|
714
714
|
end
|
@@ -716,135 +716,135 @@ describe ProgressBar::Base do
|
|
716
716
|
end
|
717
717
|
|
718
718
|
it 'displays the title when passed the "%t" format flag' do
|
719
|
-
expect(progressbar.to_s('%t')).to match
|
719
|
+
expect(progressbar.to_s('%t')).to match(/^Progress\z/)
|
720
720
|
end
|
721
721
|
|
722
722
|
it 'displays the title when passed the "%T" format flag' do
|
723
|
-
expect(progressbar.to_s('%T')).to match
|
723
|
+
expect(progressbar.to_s('%T')).to match(/^Progress\z/)
|
724
724
|
end
|
725
725
|
|
726
726
|
it 'displays the bar when passed the "%B" format flag (including empty space)' do
|
727
727
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20)
|
728
|
-
expect(progressbar.to_s('%B')).to match
|
728
|
+
expect(progressbar.to_s('%B')).to match(/^#{'=' * 20}#{' ' * 80}\z/)
|
729
729
|
end
|
730
730
|
|
731
731
|
it 'displays the bar when passed the combined "%b%i" format flags' do
|
732
732
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20)
|
733
|
-
expect(progressbar.to_s('%b%i')).to match
|
733
|
+
expect(progressbar.to_s('%b%i')).to match(/^#{'=' * 20}#{' ' * 80}\z/)
|
734
734
|
end
|
735
735
|
|
736
736
|
it 'displays the bar when passed the "%b" format flag (excluding empty space)' do
|
737
737
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20)
|
738
|
-
expect(progressbar.to_s('%b')).to match
|
738
|
+
expect(progressbar.to_s('%b')).to match(/^#{'=' * 20}\z/)
|
739
739
|
end
|
740
740
|
|
741
741
|
it 'displays the incomplete space when passed the "%i" format flag' do
|
742
742
|
progressbar = ProgressBar::Base.new(:length => 100, :starting_at => 20)
|
743
|
-
expect(progressbar.to_s('%i')).to match
|
743
|
+
expect(progressbar.to_s('%i')).to match(/^#{' ' * 80}\z/)
|
744
744
|
end
|
745
745
|
|
746
746
|
it 'displays the bar when passed the "%w" format flag' do
|
747
747
|
progressbar = ProgressBar::Base.new(:output => output, :length => 100, :starting_at => 0)
|
748
748
|
|
749
|
-
expect(progressbar.to_s('%w')).to match
|
749
|
+
expect(progressbar.to_s('%w')).to match(/^\z/)
|
750
750
|
4.times { progressbar.increment }
|
751
|
-
expect(progressbar.to_s('%w')).to match
|
751
|
+
expect(progressbar.to_s('%w')).to match(/^====\z/)
|
752
752
|
progressbar.increment
|
753
|
-
expect(progressbar.to_s('%w')).to match
|
753
|
+
expect(progressbar.to_s('%w')).to match(/^= 5 =\z/)
|
754
754
|
5.times { progressbar.increment }
|
755
|
-
expect(progressbar.to_s('%w')).to match
|
755
|
+
expect(progressbar.to_s('%w')).to match(/^=== 10 ===\z/)
|
756
756
|
progressbar.decrement
|
757
|
-
expect(progressbar.to_s('%w')).to match
|
757
|
+
expect(progressbar.to_s('%w')).to match(/^=== 9 ===\z/)
|
758
758
|
91.times { progressbar.increment }
|
759
|
-
expect(progressbar.to_s('%w')).to match
|
759
|
+
expect(progressbar.to_s('%w')).to match(/^#{'=' * 47} 100 #{'=' * 48}\z/)
|
760
760
|
end
|
761
761
|
|
762
762
|
it 'calculates the remaining negative space properly with an integrated percentage bar of 0 percent' do
|
763
763
|
progressbar = ProgressBar::Base.new(:output => output, :length => 100, :total => 200, :starting_at => 0)
|
764
764
|
|
765
|
-
expect(progressbar.to_s('%w%i')).to match
|
765
|
+
expect(progressbar.to_s('%w%i')).to match(/^\s{100}\z/)
|
766
766
|
9.times { progressbar.increment }
|
767
|
-
expect(progressbar.to_s('%w%i')).to match
|
767
|
+
expect(progressbar.to_s('%w%i')).to match(/^====\s{96}\z/)
|
768
768
|
progressbar.increment
|
769
|
-
expect(progressbar.to_s('%w%i')).to match
|
769
|
+
expect(progressbar.to_s('%w%i')).to match(/^= 5 =\s{95}\z/)
|
770
770
|
end
|
771
771
|
|
772
772
|
it 'can display a percentage, even if the total is unknown' do
|
773
773
|
progressbar = ProgressBar::Base.new(:output => output, :length => 100, :total => nil, :starting_at => 0)
|
774
774
|
|
775
|
-
expect(progressbar.to_s('%p')).to match
|
776
|
-
expect(progressbar.to_s('%P')).to match
|
775
|
+
expect(progressbar.to_s('%p')).to match(/\A0\z/)
|
776
|
+
expect(progressbar.to_s('%P')).to match(/\A0\.0\z/)
|
777
777
|
end
|
778
778
|
|
779
779
|
it 'can display a percentage, even if the total is zero' do
|
780
780
|
progressbar = ProgressBar::Base.new(:output => output, :length => 100, :total => 0, :starting_at => 0)
|
781
781
|
|
782
|
-
expect(progressbar.to_s('%p')).to match
|
783
|
-
expect(progressbar.to_s('%P')).to match
|
782
|
+
expect(progressbar.to_s('%p')).to match(/\A100\z/)
|
783
|
+
expect(progressbar.to_s('%P')).to match(/\A100\.0\z/)
|
784
784
|
end
|
785
785
|
|
786
786
|
it 'displays the current capacity when passed the "%c" format flag' do
|
787
787
|
progressbar = ProgressBar::Base.new(:output => output, :starting_at => 0)
|
788
788
|
|
789
|
-
expect(progressbar.to_s('%c')).to match
|
789
|
+
expect(progressbar.to_s('%c')).to match(/^0\z/)
|
790
790
|
progressbar.increment
|
791
|
-
expect(progressbar.to_s('%c')).to match
|
791
|
+
expect(progressbar.to_s('%c')).to match(/^1\z/)
|
792
792
|
progressbar.decrement
|
793
|
-
expect(progressbar.to_s('%c')).to match
|
793
|
+
expect(progressbar.to_s('%c')).to match(/^0\z/)
|
794
794
|
end
|
795
795
|
|
796
796
|
it 'displays the total capacity when passed the "%C" format flag' do
|
797
797
|
progressbar = ProgressBar::Base.new(:total => 100)
|
798
798
|
|
799
|
-
expect(progressbar.to_s('%C')).to match
|
799
|
+
expect(progressbar.to_s('%C')).to match(/^100\z/)
|
800
800
|
end
|
801
801
|
|
802
802
|
it 'displays the percentage complete when passed the "%p" format flag' do
|
803
803
|
progressbar = ProgressBar::Base.new(:starting_at => 33, :total => 200)
|
804
804
|
|
805
|
-
expect(progressbar.to_s('%p')).to match
|
805
|
+
expect(progressbar.to_s('%p')).to match(/^16\z/)
|
806
806
|
end
|
807
807
|
|
808
808
|
it 'displays the justified percentage complete when passed the "%j" format flag' do
|
809
809
|
progressbar = ProgressBar::Base.new(:starting_at => 33, :total => 200)
|
810
810
|
|
811
|
-
expect(progressbar.to_s('%j')).to match
|
811
|
+
expect(progressbar.to_s('%j')).to match(/^ 16\z/)
|
812
812
|
end
|
813
813
|
|
814
814
|
it 'displays the percentage complete when passed the "%P" format flag' do
|
815
815
|
progressbar = ProgressBar::Base.new(:starting_at => 33, :total => 200)
|
816
816
|
|
817
|
-
expect(progressbar.to_s('%P')).to match
|
817
|
+
expect(progressbar.to_s('%P')).to match(/^16.50\z/)
|
818
818
|
end
|
819
819
|
|
820
820
|
it 'displays the justified percentage complete when passed the "%J" format flag' do
|
821
821
|
progressbar = ProgressBar::Base.new(:starting_at => 33, :total => 200)
|
822
822
|
|
823
|
-
expect(progressbar.to_s('%J')).to match
|
823
|
+
expect(progressbar.to_s('%J')).to match(/^ 16.50\z/)
|
824
824
|
end
|
825
825
|
|
826
826
|
it 'displays only up to 2 decimal places when using the "%P" flag' do
|
827
827
|
progressbar = ProgressBar::Base.new(:starting_at => 66, :total => 99)
|
828
828
|
|
829
|
-
expect(progressbar.to_s('%P')).to match
|
829
|
+
expect(progressbar.to_s('%P')).to match(/^66.66\z/)
|
830
830
|
end
|
831
831
|
|
832
832
|
it 'displays a literal percent sign when using the "%%" flag' do
|
833
833
|
progressbar = ProgressBar::Base.new(:starting_at => 66, :total => 99)
|
834
834
|
|
835
|
-
expect(progressbar.to_s('%%')).to match
|
835
|
+
expect(progressbar.to_s('%%')).to match(/^%\z/)
|
836
836
|
end
|
837
837
|
|
838
838
|
it 'displays a literal percent sign when using the "%%" flag' do
|
839
839
|
progressbar = ProgressBar::Base.new(:starting_at => 66, :total => 99)
|
840
840
|
|
841
|
-
expect(progressbar.to_s('%%')).to match
|
841
|
+
expect(progressbar.to_s('%%')).to match(/^%\z/)
|
842
842
|
end
|
843
843
|
|
844
844
|
# Autostarting for now. This will be applicable later.
|
845
845
|
# context "when called before #start" do
|
846
846
|
# it "displays unknown time elapsed when using the %a flag" do
|
847
|
-
# expect(progressbar.to_s('%a')).to match
|
847
|
+
# expect(progressbar.to_s('%a')).to match(/^Time: --:--:--\z/)
|
848
848
|
# end
|
849
849
|
# end
|
850
850
|
|
@@ -859,19 +859,19 @@ describe ProgressBar::Base do
|
|
859
859
|
before { progressbar.reset }
|
860
860
|
|
861
861
|
it 'displays "??:??:??" until finished when passed the %e flag' do
|
862
|
-
expect(progressbar.to_s('%a')).to match
|
862
|
+
expect(progressbar.to_s('%a')).to match(/^Time: --:--:--\z/)
|
863
863
|
end
|
864
864
|
end
|
865
865
|
|
866
866
|
it 'displays the time elapsed when using the "%a" flag' do
|
867
|
-
expect(progressbar.to_s('%a')).to match
|
867
|
+
expect(progressbar.to_s('%a')).to match(/^Time: 01:02:03\z/)
|
868
868
|
end
|
869
869
|
end
|
870
870
|
|
871
871
|
context 'when called before #start' do
|
872
872
|
it 'displays unknown time until finished when passed the "%e" flag' do
|
873
873
|
progressbar = ProgressBar::Base.new
|
874
|
-
expect(progressbar.to_s('%e')).to match
|
874
|
+
expect(progressbar.to_s('%e')).to match(/^ ETA: \?\?:\?\?:\?\?\z/)
|
875
875
|
end
|
876
876
|
end
|
877
877
|
|
@@ -889,12 +889,12 @@ describe ProgressBar::Base do
|
|
889
889
|
before { progressbar.reset }
|
890
890
|
|
891
891
|
it 'displays "??:??:??" until finished when passed the "%e" flag' do
|
892
|
-
expect(progressbar.to_s('%e')).to match
|
892
|
+
expect(progressbar.to_s('%e')).to match(/^ ETA: \?\?:\?\?:\?\?\z/)
|
893
893
|
end
|
894
894
|
end
|
895
895
|
|
896
896
|
it 'displays the estimated time remaining when using the "%e" flag' do
|
897
|
-
expect(progressbar.to_s('%e')).to match
|
897
|
+
expect(progressbar.to_s('%e')).to match(/^ ETA: 01:02:03\z/)
|
898
898
|
end
|
899
899
|
end
|
900
900
|
|
@@ -909,15 +909,15 @@ describe ProgressBar::Base do
|
|
909
909
|
end
|
910
910
|
|
911
911
|
it 'displays "> 4 Days" until finished when passed the "%E" flag' do
|
912
|
-
expect(progressbar.to_s('%E')).to match
|
912
|
+
expect(progressbar.to_s('%E')).to match(/^ ETA: > 4 Days\z/)
|
913
913
|
end
|
914
914
|
|
915
915
|
it 'displays "??:??:??" until finished when passed the "%e" flag' do
|
916
|
-
expect(progressbar.to_s('%e')).to match
|
916
|
+
expect(progressbar.to_s('%e')).to match(/^ ETA: \?\?:\?\?:\?\?\z/)
|
917
917
|
end
|
918
918
|
|
919
919
|
it 'displays the exact estimated time until finished when passed the "%f" flag' do
|
920
|
-
expect(progressbar.to_s('%f')).to match
|
920
|
+
expect(progressbar.to_s('%f')).to match(/^ ETA: 100:00:00\z/)
|
921
921
|
end
|
922
922
|
end
|
923
923
|
end
|
data/spec/spec_helper.rb
ADDED
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.6.
|
4
|
+
version: 1.6.1
|
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-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 2.0beta
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: warning_filter
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.0.2
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.0.2
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: timecop
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,12 +102,11 @@ description: |
|
|
88
102
|
email: support@thekompanee.com
|
89
103
|
executables: []
|
90
104
|
extensions: []
|
91
|
-
extra_rdoc_files:
|
92
|
-
- README.md
|
93
|
-
- LICENSE
|
105
|
+
extra_rdoc_files: []
|
94
106
|
files:
|
95
107
|
- LICENSE
|
96
108
|
- README.md
|
109
|
+
- Rakefile
|
97
110
|
- lib/ruby-progressbar.rb
|
98
111
|
- lib/ruby-progressbar/base.rb
|
99
112
|
- lib/ruby-progressbar/components.rb
|
@@ -123,15 +136,14 @@ files:
|
|
123
136
|
- spec/lib/ruby-progressbar/format/molecule_spec.rb
|
124
137
|
- spec/lib/ruby-progressbar/running_average_calculator_spec.rb
|
125
138
|
- spec/lib/ruby-progressbar/time_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
126
140
|
- spec/support/time.rb
|
127
141
|
homepage: https://github.com/jfelchner/ruby-progressbar
|
128
142
|
licenses:
|
129
143
|
- MIT
|
130
144
|
metadata: {}
|
131
145
|
post_install_message:
|
132
|
-
rdoc_options:
|
133
|
-
- "--charset"
|
134
|
-
- UTF-8
|
146
|
+
rdoc_options: []
|
135
147
|
require_paths:
|
136
148
|
- lib
|
137
149
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -146,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
158
|
version: '0'
|
147
159
|
requirements: []
|
148
160
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.4.2
|
150
162
|
signing_key:
|
151
163
|
specification_version: 4
|
152
164
|
summary: Ruby/ProgressBar is a flexible text progress bar library for Ruby.
|
@@ -161,5 +173,6 @@ test_files:
|
|
161
173
|
- spec/lib/ruby-progressbar/format/molecule_spec.rb
|
162
174
|
- spec/lib/ruby-progressbar/running_average_calculator_spec.rb
|
163
175
|
- spec/lib/ruby-progressbar/time_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
164
177
|
- spec/support/time.rb
|
165
178
|
has_rdoc:
|