ruby-progressbar 1.6.1 → 1.7.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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/ruby-progressbar.rb +8 -3
  4. data/lib/ruby-progressbar/base.rb +121 -177
  5. data/lib/ruby-progressbar/calculators/length.rb +75 -0
  6. data/lib/ruby-progressbar/calculators/length_spec.rb +9 -0
  7. data/lib/ruby-progressbar/calculators/running_average.rb +9 -0
  8. data/lib/ruby-progressbar/components.rb +3 -5
  9. data/lib/ruby-progressbar/components/bar.rb +79 -43
  10. data/lib/ruby-progressbar/components/percentage.rb +29 -0
  11. data/lib/ruby-progressbar/components/rate.rb +34 -62
  12. data/lib/ruby-progressbar/components/time.rb +103 -0
  13. data/lib/ruby-progressbar/components/title.rb +13 -0
  14. data/lib/ruby-progressbar/format.rb +2 -1
  15. data/lib/ruby-progressbar/format/formatter.rb +27 -0
  16. data/lib/ruby-progressbar/format/molecule.rb +55 -37
  17. data/lib/ruby-progressbar/format/string.rb +36 -0
  18. data/lib/ruby-progressbar/output.rb +61 -0
  19. data/lib/ruby-progressbar/outputs/non_tty.rb +47 -0
  20. data/lib/ruby-progressbar/outputs/tty.rb +32 -0
  21. data/lib/ruby-progressbar/progress.rb +110 -0
  22. data/lib/ruby-progressbar/throttle.rb +25 -0
  23. data/lib/ruby-progressbar/time.rb +20 -17
  24. data/lib/ruby-progressbar/timer.rb +72 -0
  25. data/lib/ruby-progressbar/version.rb +2 -2
  26. data/spec/fixtures/benchmark.rb +21 -4
  27. data/spec/{lib/ruby-progressbar → ruby-progressbar}/base_spec.rb +55 -62
  28. data/spec/ruby-progressbar/calculators/running_average_spec.rb +19 -0
  29. data/spec/ruby-progressbar/components/bar_spec.rb +234 -0
  30. data/spec/ruby-progressbar/components/percentage_spec.rb +9 -0
  31. data/spec/ruby-progressbar/components/rate_spec.rb +9 -0
  32. data/spec/ruby-progressbar/components/throttle_spec.rb +157 -0
  33. data/spec/ruby-progressbar/components/time_spec.rb +308 -0
  34. data/spec/ruby-progressbar/components/title_spec.rb +12 -0
  35. data/spec/ruby-progressbar/format/formatter_spec.rb +9 -0
  36. data/spec/ruby-progressbar/format/molecule_spec.rb +30 -0
  37. data/spec/ruby-progressbar/format/string_spec.rb +9 -0
  38. data/spec/ruby-progressbar/output_spec.rb +7 -0
  39. data/spec/ruby-progressbar/outputs/non_tty_spec.rb +9 -0
  40. data/spec/ruby-progressbar/outputs/tty_spec.rb +9 -0
  41. data/spec/ruby-progressbar/progress_spec.rb +150 -0
  42. data/spec/ruby-progressbar/time_spec.rb +37 -0
  43. data/spec/ruby-progressbar/timer_spec.rb +7 -0
  44. data/spec/spec_helper.rb +2 -2
  45. data/spec/support/time.rb +3 -1
  46. metadata +55 -35
  47. data/lib/ruby-progressbar/components/elapsed_timer.rb +0 -25
  48. data/lib/ruby-progressbar/components/estimated_timer.rb +0 -90
  49. data/lib/ruby-progressbar/components/progressable.rb +0 -112
  50. data/lib/ruby-progressbar/components/throttle.rb +0 -21
  51. data/lib/ruby-progressbar/components/timer.rb +0 -69
  52. data/lib/ruby-progressbar/format/base.rb +0 -55
  53. data/lib/ruby-progressbar/formatter.rb +0 -112
  54. data/lib/ruby-progressbar/length_calculator.rb +0 -64
  55. data/lib/ruby-progressbar/running_average_calculator.rb +0 -7
  56. data/spec/lib/ruby-progressbar/components/bar_spec.rb +0 -210
  57. data/spec/lib/ruby-progressbar/components/elapsed_timer_spec.rb +0 -91
  58. data/spec/lib/ruby-progressbar/components/estimated_timer_spec.rb +0 -241
  59. data/spec/lib/ruby-progressbar/components/progressable_spec.rb +0 -47
  60. data/spec/lib/ruby-progressbar/components/throttle_spec.rb +0 -100
  61. data/spec/lib/ruby-progressbar/format/molecule_spec.rb +0 -22
  62. data/spec/lib/ruby-progressbar/running_average_calculator_spec.rb +0 -11
  63. data/spec/lib/ruby-progressbar/time_spec.rb +0 -49
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class ProgressableClass
4
- include ProgressBar::Components::Progressable
5
- end
6
-
7
- describe ProgressBar::Components::Progressable do
8
- subject { ProgressableClass.new }
9
-
10
- describe '#running_average' do
11
- it 'is properly calculated when progress has been made' do
12
- subject.running_average = 10
13
- subject.start :at => 0
14
- expect(subject.running_average).to be_zero
15
-
16
- subject.progress += 40
17
- expect(subject.running_average).to eql 36.0
18
- end
19
-
20
- it 'is always reset when the progressable is started' do
21
- subject.running_average = 10
22
- subject.start :at => 0
23
- expect(subject.running_average).to be_zero
24
-
25
- subject.start :at => 40
26
- expect(subject.running_average).to eql 0.0
27
- end
28
- end
29
-
30
- describe '#smoothing' do
31
- it 'can be passed in as an option to the initializer' do
32
- expect(ProgressableClass.new(:smoothing => 0.3).smoothing).to eql 0.3
33
- end
34
-
35
- it 'does not have to be passed in as an option to the initializer' do
36
- expect(ProgressableClass.new.smoothing).to eql 0.1
37
- end
38
- end
39
-
40
- describe '#percentage_completed' do
41
- it 'returns the default total if total is zero' do
42
- subject.total = 0
43
-
44
- expect(subject.percentage_completed).to eql 100
45
- end
46
- end
47
- end
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ProgressBar::Components::Throttle do
4
- context 'given a numeric period' do
5
- before do
6
- Timecop.freeze(0) {
7
- @throttle = ProgressBar::Components::Throttle.new(:throttle_rate => 10)
8
- }
9
- end
10
-
11
- describe '#choke' do
12
- it 'yields the first time' do
13
- yielded = false
14
-
15
- @throttle.choke { yielded = true }
16
-
17
- expect(yielded).to eql true
18
- end
19
-
20
- context 'after initial yield', :time_mock do
21
- before do
22
- @throttle.choke { }
23
- end
24
-
25
- it "doesn't yield if period hasn't passed yet" do
26
- yielded = false
27
-
28
- (1..9).each do |t|
29
- Timecop.freeze(t) { @throttle.choke { yielded = true } }
30
-
31
- expect(yielded).to eql false
32
- end
33
- end
34
-
35
- it 'always yields if passed true' do
36
- yielded = -1
37
-
38
- (0..25).each do |t|
39
- Timecop.freeze(t) { @throttle.choke(true) { yielded += 1 } }
40
-
41
- expect(yielded).to eql t
42
- end
43
- end
44
-
45
- it "yields after period has passed" do
46
- yielded = false
47
-
48
- Timecop.freeze(15) { @throttle.choke { yielded = true } }
49
-
50
- expect(yielded).to eql true
51
- end
52
- end
53
-
54
- context 'after a yield' do
55
- before do
56
- Timecop.freeze(0) { @throttle.choke { } }
57
- Timecop.freeze(15) { @throttle.choke { } }
58
- end
59
-
60
- it "doesn't yield if period hasn't passed yet" do
61
- yielded = false
62
-
63
- (16..24).each do |t|
64
- Timecop.freeze(t) { @throttle.choke { yielded = true } }
65
-
66
- expect(yielded).to eql false
67
- end
68
- end
69
-
70
- it "yields after period has passed" do
71
- yielded = false
72
-
73
- Timecop.freeze(25) { @throttle.choke { yielded = true } }
74
-
75
- expect(yielded).to eql true
76
- end
77
- end
78
- end
79
- end
80
-
81
- context 'given no throttle period' do
82
- before do
83
- Timecop.freeze(0) {
84
- @throttle = ProgressBar::Components::Throttle.new()
85
- }
86
- end
87
-
88
- describe '#choke' do
89
- it 'yields every time' do
90
- yielded = -1
91
-
92
- (0..25).each do |t|
93
- Timecop.freeze(t) { @throttle.choke { yielded += 1 } }
94
-
95
- expect(yielded).to eql t
96
- end
97
- end
98
- end
99
- end
100
- end
@@ -1,22 +0,0 @@
1
- require 'rspectacular'
2
-
3
- describe ProgressBar::Format::Molecule do
4
- describe '#new' do
5
- before { @molecule = ProgressBar::Format::Molecule.new('e') }
6
-
7
- it 'sets the key when initialized' do
8
- expect(@molecule.key).to eql 'e'
9
- end
10
-
11
- it 'sets the method name when initialized' do
12
- expect(@molecule.method_name).to eql :estimated_time_with_unknown_oob
13
- end
14
- end
15
-
16
- describe '#bar_molecule?' do
17
- it "is true if the molecule's key is a representation of the progress bar graphic" do
18
- molecule = ProgressBar::Format::Molecule.new('B')
19
- expect(molecule).to be_bar_molecule
20
- end
21
- end
22
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ProgressBar::RunningAverageCalculator do
4
- describe '.calculate' do
5
- it 'calculates properly' do
6
- expect(ProgressBar::RunningAverageCalculator.calculate(4.5, 12, 0.1)).to be_within(0.001).of 11.25
7
- expect(ProgressBar::RunningAverageCalculator.calculate(8.2, 51, 0.7)).to be_within(0.001).of 21.04
8
- expect(ProgressBar::RunningAverageCalculator.calculate(41.8, 100, 0.59)).to be_within(0.001).of 65.662
9
- end
10
- end
11
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TimeMockedWithTimecop
4
- def self.now; end
5
- def self.now_without_mock_time; end
6
- end
7
-
8
- class TimeMockedWithDelorean
9
- def self.now; end
10
- def self.now_without_delorean; end
11
- end
12
-
13
- class UnmockedTime
14
- def self.now; end
15
- end
16
-
17
- describe ProgressBar::Time do
18
- describe '#now' do
19
- context 'when Time is being mocked by Timecop' do
20
- subject { ProgressBar::Time.now ::TimeMockedWithTimecop }
21
-
22
- it 'retrieves the unmocked Timecop time' do
23
- allow(::TimeMockedWithTimecop).to receive(:now_without_mock_time).once
24
-
25
- subject
26
- end
27
- end
28
-
29
- context 'when Time is being mocked by Delorean' do
30
- subject { ProgressBar::Time.now ::TimeMockedWithDelorean }
31
-
32
- it 'retrieves the unmocked Delorean time' do
33
- allow(::TimeMockedWithDelorean).to receive(:now_without_delorean).once
34
-
35
- subject
36
- end
37
- end
38
-
39
- context 'when Time is not being mocked' do
40
- subject { ProgressBar::Time.now ::UnmockedTime }
41
-
42
- it 'will return the actual time' do
43
- allow(::UnmockedTime).to receive(:now).once
44
-
45
- subject
46
- end
47
- end
48
- end
49
- end