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
@@ -0,0 +1,12 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/components/title'
3
+
4
+ class ProgressBar
5
+ module Components
6
+ describe Title do
7
+ it 'can use the default title if none is specified' do
8
+ expect(Title.new.title).to eql Title::DEFAULT_TITLE
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/format/formatter'
3
+
4
+ class ProgressBar
5
+ module Format
6
+ describe Formatter do
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/format/molecule'
3
+
4
+ class ProgressBar
5
+ module Format
6
+ describe Molecule do
7
+ it 'sets the key when initialized' do
8
+ molecule = Molecule.new('t')
9
+
10
+ expect(molecule.key).to eql 't'
11
+ end
12
+
13
+ it 'sets the method name when initialized' do
14
+ molecule = Molecule.new('t')
15
+
16
+ expect(molecule.method_name).to eql [:title_comp, :title]
17
+ end
18
+
19
+ it 'can retrieve the full key for itself' do
20
+ molecule = Molecule.new('t')
21
+
22
+ expect(molecule.full_key).to eql '%t'
23
+ end
24
+
25
+ it 'can determine if it is a bar molecule' do
26
+ expect(Molecule.new('B')).to be_bar_molecule
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/format/string'
3
+
4
+ class ProgressBar
5
+ module Format
6
+ describe String do
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/output'
3
+
4
+ class ProgressBar
5
+ describe Output do
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/outputs/non_tty'
3
+
4
+ class ProgressBar
5
+ module Outputs
6
+ describe NonTty do
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/outputs/tty'
3
+
4
+ class ProgressBar
5
+ module Outputs
6
+ describe Tty do
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,150 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/progress'
3
+
4
+ class ProgressBar
5
+ describe Progress do
6
+ it 'knows the default total when no parameters are passed' do
7
+ progress = Progress.new
8
+
9
+ expect(progress.total).to eql Progress::DEFAULT_TOTAL
10
+ end
11
+
12
+ it 'knows the default beginning progress when no parameters are passed and ' \
13
+ 'the progress has not been started' do
14
+
15
+ progress = Progress.new
16
+
17
+ expect(progress.progress).to be_zero
18
+ end
19
+
20
+ it 'knows the default starting value when no parameters are passed and the ' \
21
+ 'progress has been started' do
22
+
23
+ progress = Progress.new
24
+
25
+ progress.start
26
+
27
+ expect(progress.progress).to eql Progress::DEFAULT_BEGINNING_POSITION
28
+ end
29
+
30
+ it 'knows the given starting value when no parameters are passed and the ' \
31
+ 'progress is started with a starting value' do
32
+
33
+ progress = Progress.new
34
+
35
+ progress.start :at => 10
36
+
37
+ expect(progress.progress).to eql 10
38
+ end
39
+
40
+ it 'knows the overridden total when the total is passed in' do
41
+ progress = Progress.new(:total => 12,
42
+ :progress_mark => 'x',
43
+ :remainder_mark => '.')
44
+
45
+ expect(progress.total).to eql 12
46
+ end
47
+
48
+ it 'knows the percentage completed when begun with no progress' do
49
+ progress = Progress.new
50
+
51
+ progress.start
52
+
53
+ expect(progress.percentage_completed).to eql 0
54
+ end
55
+
56
+ it 'knows the progress after it has been incremented' do
57
+ progress = Progress.new
58
+
59
+ progress.start
60
+ progress.increment
61
+
62
+ expect(progress.progress).to eql 1
63
+ end
64
+
65
+ it 'knows the percentage completed after it has been incremented' do
66
+ progress = Progress.new(:total => 50)
67
+
68
+ progress.start
69
+ progress.increment
70
+
71
+ expect(progress.percentage_completed).to eql 2
72
+ end
73
+
74
+ it 'knows to always round down the percentage completed' do
75
+ progress = Progress.new(:total => 200)
76
+
77
+ progress.start :at => 1
78
+
79
+ expect(progress.percentage_completed).to eql 0
80
+ end
81
+
82
+ it 'cannot increment past the total' do
83
+ progress = Progress.new(:total => 50)
84
+
85
+ progress.start :at => 50
86
+ progress.increment
87
+
88
+ expect(progress.progress).to eql 50
89
+ expect(progress.percentage_completed).to eql 100
90
+ end
91
+
92
+ it 'allow progress to be decremented once it is finished' do
93
+ progress = Progress.new(:total => 50)
94
+
95
+ progress.start :at => 50
96
+ progress.decrement
97
+
98
+ expect(progress.progress).to eql 49
99
+ expect(progress.percentage_completed).to eql 98
100
+ end
101
+
102
+ it 'knows the running average even when progress has been made' do
103
+ progress = Progress.new(:total => 50)
104
+
105
+ progress.running_average = 10
106
+ progress.start :at => 0
107
+
108
+ expect(progress.running_average).to be_zero
109
+
110
+ progress.progress += 40
111
+
112
+ expect(progress.running_average).to eql 36.0
113
+ end
114
+
115
+ it 'knows the running average is reset even after progress is started' do
116
+ progress = Progress.new(:total => 50)
117
+
118
+ progress.running_average = 10
119
+ progress.start :at => 0
120
+
121
+ expect(progress.running_average).to be_zero
122
+
123
+ progress.start :at => 40
124
+
125
+ expect(progress.running_average).to eql 0.0
126
+ end
127
+
128
+ it 'allows the default smoothing to be overridden' do
129
+ expect(Progress.new(:smoothing => 0.3).smoothing).to eql 0.3
130
+ end
131
+
132
+ it 'has a default smoothing value' do
133
+ expect(Progress.new.smoothing).to eql 0.1
134
+ end
135
+
136
+ it 'knows the percentage completed is 100% if the total is zero' do
137
+ progress = Progress.new(:total => 0)
138
+
139
+ expect(progress.percentage_completed).to eql 100
140
+ end
141
+
142
+ it 'raises an error when passed a number larger than the total' do
143
+ progress = Progress.new(:total => 100)
144
+
145
+ expect { progress.progress = 101 }.to \
146
+ raise_error(InvalidProgressError,
147
+ "You can't set the item's current value to be greater than the total.")
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,37 @@
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
+ class ProgressBar
18
+ describe Time do
19
+ it 'when Time is being mocked by Timecop retrieves the unmocked Timecop time' do
20
+ allow(TimeMockedWithTimecop).to receive(:now_without_mock_time).once
21
+
22
+ Time.now(TimeMockedWithTimecop)
23
+ end
24
+
25
+ it 'when Time is being mocked by Delorean retrieves the unmocked Delorean time' do
26
+ allow(TimeMockedWithDelorean).to receive(:now_without_delorean).once
27
+
28
+ Time.now(TimeMockedWithDelorean)
29
+ end
30
+
31
+ it 'when Time is not being mocked will return the actual time' do
32
+ allow(UnmockedTime).to receive(:now).once
33
+
34
+ Time.now(UnmockedTime)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspectacular'
2
+ require 'ruby-progressbar/timer'
3
+
4
+ class ProgressBar
5
+ describe Timer do
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
- require "rspectacular"
2
- require "warning_filter"
1
+ require 'rspectacular'
2
+ require 'warning_filter'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  config.warnings = true
@@ -8,7 +8,8 @@ class PBTimeTester
8
8
  end
9
9
  end
10
10
 
11
- class ::ProgressBar::Time
11
+ class ProgressBar
12
+ class Time
12
13
  class << self
13
14
  alias_method :old_now, :now
14
15
 
@@ -17,3 +18,4 @@ class ::ProgressBar::Time
17
18
  end
18
19
  end
19
20
  end
21
+ end
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.1
4
+ version: 1.7.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-10-30 00:00:00.000000000 Z
12
+ date: 2014-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 3.0.0beta
20
+ version: '3.1'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 3.0.0beta
27
+ version: '3.1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspectacular
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 2.0beta
48
+ version: '2.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 2.0beta
55
+ version: '2.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: warning_filter
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -109,33 +109,46 @@ files:
109
109
  - Rakefile
110
110
  - lib/ruby-progressbar.rb
111
111
  - lib/ruby-progressbar/base.rb
112
+ - lib/ruby-progressbar/calculators/length.rb
113
+ - lib/ruby-progressbar/calculators/length_spec.rb
114
+ - lib/ruby-progressbar/calculators/running_average.rb
112
115
  - lib/ruby-progressbar/components.rb
113
116
  - lib/ruby-progressbar/components/bar.rb
114
- - lib/ruby-progressbar/components/elapsed_timer.rb
115
- - lib/ruby-progressbar/components/estimated_timer.rb
116
- - lib/ruby-progressbar/components/progressable.rb
117
+ - lib/ruby-progressbar/components/percentage.rb
117
118
  - lib/ruby-progressbar/components/rate.rb
118
- - lib/ruby-progressbar/components/throttle.rb
119
- - lib/ruby-progressbar/components/timer.rb
119
+ - lib/ruby-progressbar/components/time.rb
120
+ - lib/ruby-progressbar/components/title.rb
120
121
  - lib/ruby-progressbar/errors/invalid_progress_error.rb
121
122
  - lib/ruby-progressbar/format.rb
122
- - lib/ruby-progressbar/format/base.rb
123
+ - lib/ruby-progressbar/format/formatter.rb
123
124
  - lib/ruby-progressbar/format/molecule.rb
124
- - lib/ruby-progressbar/formatter.rb
125
- - lib/ruby-progressbar/length_calculator.rb
126
- - lib/ruby-progressbar/running_average_calculator.rb
125
+ - lib/ruby-progressbar/format/string.rb
126
+ - lib/ruby-progressbar/output.rb
127
+ - lib/ruby-progressbar/outputs/non_tty.rb
128
+ - lib/ruby-progressbar/outputs/tty.rb
129
+ - lib/ruby-progressbar/progress.rb
130
+ - lib/ruby-progressbar/throttle.rb
127
131
  - lib/ruby-progressbar/time.rb
132
+ - lib/ruby-progressbar/timer.rb
128
133
  - lib/ruby-progressbar/version.rb
129
134
  - spec/fixtures/benchmark.rb
130
- - spec/lib/ruby-progressbar/base_spec.rb
131
- - spec/lib/ruby-progressbar/components/bar_spec.rb
132
- - spec/lib/ruby-progressbar/components/elapsed_timer_spec.rb
133
- - spec/lib/ruby-progressbar/components/estimated_timer_spec.rb
134
- - spec/lib/ruby-progressbar/components/progressable_spec.rb
135
- - spec/lib/ruby-progressbar/components/throttle_spec.rb
136
- - spec/lib/ruby-progressbar/format/molecule_spec.rb
137
- - spec/lib/ruby-progressbar/running_average_calculator_spec.rb
138
- - spec/lib/ruby-progressbar/time_spec.rb
135
+ - spec/ruby-progressbar/base_spec.rb
136
+ - spec/ruby-progressbar/calculators/running_average_spec.rb
137
+ - spec/ruby-progressbar/components/bar_spec.rb
138
+ - spec/ruby-progressbar/components/percentage_spec.rb
139
+ - spec/ruby-progressbar/components/rate_spec.rb
140
+ - spec/ruby-progressbar/components/throttle_spec.rb
141
+ - spec/ruby-progressbar/components/time_spec.rb
142
+ - spec/ruby-progressbar/components/title_spec.rb
143
+ - spec/ruby-progressbar/format/formatter_spec.rb
144
+ - spec/ruby-progressbar/format/molecule_spec.rb
145
+ - spec/ruby-progressbar/format/string_spec.rb
146
+ - spec/ruby-progressbar/output_spec.rb
147
+ - spec/ruby-progressbar/outputs/non_tty_spec.rb
148
+ - spec/ruby-progressbar/outputs/tty_spec.rb
149
+ - spec/ruby-progressbar/progress_spec.rb
150
+ - spec/ruby-progressbar/time_spec.rb
151
+ - spec/ruby-progressbar/timer_spec.rb
139
152
  - spec/spec_helper.rb
140
153
  - spec/support/time.rb
141
154
  homepage: https://github.com/jfelchner/ruby-progressbar
@@ -158,21 +171,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
171
  version: '0'
159
172
  requirements: []
160
173
  rubyforge_project:
161
- rubygems_version: 2.4.2
174
+ rubygems_version: 2.2.2
162
175
  signing_key:
163
176
  specification_version: 4
164
177
  summary: Ruby/ProgressBar is a flexible text progress bar library for Ruby.
165
178
  test_files:
166
179
  - spec/fixtures/benchmark.rb
167
- - spec/lib/ruby-progressbar/base_spec.rb
168
- - spec/lib/ruby-progressbar/components/bar_spec.rb
169
- - spec/lib/ruby-progressbar/components/elapsed_timer_spec.rb
170
- - spec/lib/ruby-progressbar/components/estimated_timer_spec.rb
171
- - spec/lib/ruby-progressbar/components/progressable_spec.rb
172
- - spec/lib/ruby-progressbar/components/throttle_spec.rb
173
- - spec/lib/ruby-progressbar/format/molecule_spec.rb
174
- - spec/lib/ruby-progressbar/running_average_calculator_spec.rb
175
- - spec/lib/ruby-progressbar/time_spec.rb
180
+ - spec/ruby-progressbar/base_spec.rb
181
+ - spec/ruby-progressbar/calculators/running_average_spec.rb
182
+ - spec/ruby-progressbar/components/bar_spec.rb
183
+ - spec/ruby-progressbar/components/percentage_spec.rb
184
+ - spec/ruby-progressbar/components/rate_spec.rb
185
+ - spec/ruby-progressbar/components/throttle_spec.rb
186
+ - spec/ruby-progressbar/components/time_spec.rb
187
+ - spec/ruby-progressbar/components/title_spec.rb
188
+ - spec/ruby-progressbar/format/formatter_spec.rb
189
+ - spec/ruby-progressbar/format/molecule_spec.rb
190
+ - spec/ruby-progressbar/format/string_spec.rb
191
+ - spec/ruby-progressbar/output_spec.rb
192
+ - spec/ruby-progressbar/outputs/non_tty_spec.rb
193
+ - spec/ruby-progressbar/outputs/tty_spec.rb
194
+ - spec/ruby-progressbar/progress_spec.rb
195
+ - spec/ruby-progressbar/time_spec.rb
196
+ - spec/ruby-progressbar/timer_spec.rb
176
197
  - spec/spec_helper.rb
177
198
  - spec/support/time.rb
178
- has_rdoc: