progressbar 1.13.0rc1 → 1.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 600c4958d5a0334a7b8c57e026f018d2fbbb16e5dd03b9abc1a989a36b008466
4
- data.tar.gz: 895e70eb9b8cc7ca96d86f06e8cc8f6dd36171faa2ea61cd868541b748fdb975
3
+ metadata.gz: f418592d256e13252084abad3577d8000cdaacfdf2714c930cef99bb02690dcb
4
+ data.tar.gz: 05fe75f498f6dc53fc26ee79c5cb229359e7f4fc158e3aed861ae84b02700a4a
5
5
  SHA512:
6
- metadata.gz: cd5be8205221bd7701b32a2174465bab687195e3b764d19c1ccfa1f6a748162eaed3f2259b21f06f8d4a1070c899ef6cfc262f02e6cd7409990b7ac4295fcfe3
7
- data.tar.gz: e470d4c737a328d6aad8dbb58796408256b63c4d5efd21ef2e730141cd3ce817b6a4c0d14dec4db2165b6f73d02dcf6ee221f54432a7abd226864dd4416fcd75
6
+ metadata.gz: c56aeb64b49c3e7bc9fffcc5e79c23bd2d5a96048a39b89398506397f317a891796eedd64f8924afb0a671d37b7df0bd3528d95a58218089c4e4d1ad464e9920
7
+ data.tar.gz: b20205abe7ce6979211102f81b7157ccbd3eec58f2ed9076626dcce4eba4aa1c6763708dca35bb046b5923e3f2803f44e2955113a8a1380ac0fab03a85ae6717
checksums.yaml.gz.sig CHANGED
Binary file
@@ -10,12 +10,29 @@ require 'ruby-progressbar/format/string'
10
10
  require 'ruby-progressbar/outputs/non_tty'
11
11
  require 'ruby-progressbar/outputs/tty'
12
12
  require 'ruby-progressbar/progress'
13
+ require 'ruby-progressbar/projector'
13
14
  require 'ruby-progressbar/timer'
14
15
 
15
16
  class ProgressBar
16
17
  class Base
17
18
  extend Forwardable
18
19
 
20
+ # rubocop:disable Layout/HeredocIndentation
21
+ SMOOTHING_DEPRECATION_WARNING = <<-HEREDOC.tr("\n", ' ')
22
+ WARNING: Passing the 'smoothing' option is deprecated and will be removed
23
+ in version 2.0. Please pass { projector: { type: 'smoothing', strength: 0.x }}.
24
+ For more information on why this change is happening, visit
25
+ https://github.com/jfelchner/ruby-progressbar/wiki/Upgrading
26
+ HEREDOC
27
+
28
+ RUNNING_AVERAGE_RATE_DEPRECATION_WARNING = <<-HEREDOC.tr("\n", ' ')
29
+ WARNING: Passing the 'running_average_rate' option is deprecated and will be removed
30
+ in version 2.0. Please pass { projector: { type: 'smoothing', strength: 0.x }}.
31
+ For more information on why this change is happening, visit
32
+ https://github.com/jfelchner/ruby-progressbar/wiki/Upgrading
33
+ HEREDOC
34
+ # rubocop:enable Layout/HeredocIndentation
35
+
19
36
  def_delegators :output,
20
37
  :clear,
21
38
  :log,
@@ -26,15 +43,34 @@ class Base
26
43
  :total
27
44
 
28
45
  def initialize(options = {}) # rubocop:disable Metrics/AbcSize
46
+ options[:projector] ||= {}
47
+
29
48
  self.autostart = options.fetch(:autostart, true)
30
49
  self.autofinish = options.fetch(:autofinish, true)
31
50
  self.finished = false
32
51
 
33
52
  self.timer = Timer.new(options)
53
+ projector_opts = if options[:projector].any?
54
+ options[:projector]
55
+ elsif options[:smoothing]
56
+ warn SMOOTHING_DEPRECATION_WARNING
57
+
58
+ { :strength => options[:smoothing] }
59
+ elsif options[:running_average_rate]
60
+ warn RUNNING_AVERAGE_RATE_DEPRECATION_WARNING
61
+
62
+ { :strength => options[:smoothing] }
63
+ else
64
+ {}
65
+ end
66
+ self.projector = Projector.
67
+ from_type(options[:projector][:type]).
68
+ new(projector_opts)
34
69
  self.progressable = Progress.new(options)
35
70
 
36
- options = options.merge(:progress => progressable,
37
- :timer => timer)
71
+ options = options.merge(:progress => progressable,
72
+ :projector => projector,
73
+ :timer => timer)
38
74
 
39
75
  self.title_component = Components::Title.new(options)
40
76
  self.bar_component = Components::Bar.new(options)
@@ -79,6 +115,7 @@ class Base
79
115
  output.with_refresh do
80
116
  self.finished = false
81
117
  progressable.reset
118
+ projector.reset
82
119
  timer.reset
83
120
  end
84
121
  end
@@ -174,6 +211,7 @@ class Base
174
211
  protected
175
212
 
176
213
  attr_accessor :output,
214
+ :projector,
177
215
  :timer,
178
216
  :progressable,
179
217
  :title_component,
@@ -188,6 +226,7 @@ class Base
188
226
  def update_progress(*args)
189
227
  output.with_refresh do
190
228
  progressable.__send__(*args)
229
+ projector.__send__(*args)
191
230
  timer.stop if finished?
192
231
  end
193
232
  end
@@ -19,8 +19,9 @@ class Time
19
19
  }.freeze
20
20
 
21
21
  def initialize(options = {})
22
- self.timer = options[:timer]
23
- self.progress = options[:progress]
22
+ self.timer = options[:timer]
23
+ self.progress = options[:progress]
24
+ self.projector = options[:projector]
24
25
  end
25
26
 
26
27
  def estimated_with_label(out_of_bounds_time_format = nil)
@@ -57,7 +58,8 @@ class Time
57
58
  protected
58
59
 
59
60
  attr_accessor :timer,
60
- :progress
61
+ :progress,
62
+ :projector
61
63
 
62
64
  private
63
65
 
@@ -90,9 +92,9 @@ class Time
90
92
  end
91
93
 
92
94
  def estimated_seconds_remaining
93
- return if progress.unknown? || progress.none? || timer.stopped? || timer.reset?
95
+ return if progress.unknown? || projector.none? || progress.none? || timer.stopped? || timer.reset?
94
96
 
95
- (timer.elapsed_seconds * ((progress.total / progress.running_average) - 1)).round
97
+ (timer.elapsed_seconds * ((progress.total / projector.projection) - 1)).round
96
98
  end
97
99
  end
98
100
  end
@@ -1,40 +1,22 @@
1
1
  require 'ruby-progressbar/errors/invalid_progress_error'
2
- require 'ruby-progressbar/calculators/smoothed_average'
3
2
 
4
3
  class ProgressBar
5
4
  class Progress
6
- DEFAULT_TOTAL = 100
7
- DEFAULT_BEGINNING_POSITION = 0
8
- DEFAULT_RUNNING_AVERAGE_RATE = 0.1
9
- DEFAULT_RUNNING_AVERAGE_CALCULATOR = ProgressBar::Calculators::SmoothedAverage
10
-
11
- RUNNING_AVERAGE_CALCULATOR_MAP = {
12
- 'smoothing' => ProgressBar::Calculators::SmoothedAverage
13
- }.freeze
5
+ DEFAULT_TOTAL = 100
6
+ DEFAULT_BEGINNING_POSITION = 0
14
7
 
15
8
  attr_reader :total,
16
9
  :progress
17
-
18
- attr_accessor :starting_position,
19
- :running_average,
20
- :running_average_calculator,
21
- :running_average_rate
10
+ attr_accessor :starting_position
22
11
 
23
12
  def initialize(options = {})
24
- self.total = options.fetch(:total, DEFAULT_TOTAL)
25
- self.running_average_rate = options[:smoothing] ||
26
- options[:running_average_rate] ||
27
- DEFAULT_RUNNING_AVERAGE_RATE
28
- self.running_average_calculator = RUNNING_AVERAGE_CALCULATOR_MAP.
29
- fetch(options[:running_average_calculator],
30
- DEFAULT_RUNNING_AVERAGE_CALCULATOR)
31
-
32
- start :at => DEFAULT_BEGINNING_POSITION
13
+ self.total = options.fetch(:total, DEFAULT_TOTAL)
14
+
15
+ start(:at => DEFAULT_BEGINNING_POSITION)
33
16
  end
34
17
 
35
18
  def start(options = {})
36
- self.running_average = 0
37
- self.progress = \
19
+ self.progress = \
38
20
  self.starting_position = options[:at] || progress
39
21
  end
40
22
 
@@ -67,7 +49,7 @@ class Progress
67
49
  end
68
50
 
69
51
  def reset
70
- start :at => starting_position
52
+ start(:at => starting_position)
71
53
  end
72
54
 
73
55
  def progress=(new_progress)
@@ -77,10 +59,6 @@ class Progress
77
59
  end
78
60
 
79
61
  @progress = new_progress
80
-
81
- self.running_average = running_average_calculator.calculate(running_average,
82
- absolute,
83
- running_average_rate)
84
62
  end
85
63
 
86
64
  def total=(new_total)
@@ -105,7 +83,7 @@ class Progress
105
83
  end
106
84
 
107
85
  def none?
108
- running_average.zero? || progress.zero?
86
+ progress.zero?
109
87
  end
110
88
 
111
89
  def unknown?
@@ -0,0 +1,14 @@
1
+ require 'ruby-progressbar/projectors/smoothed_average'
2
+
3
+ class ProgressBar
4
+ class Projector
5
+ DEFAULT_PROJECTOR = ProgressBar::Projectors::SmoothedAverage
6
+ NAME_TO_PROJECTOR_MAP = {
7
+ 'smoothed' => ProgressBar::Projectors::SmoothedAverage
8
+ }.freeze
9
+
10
+ def self.from_type(name)
11
+ NAME_TO_PROJECTOR_MAP.fetch(name, DEFAULT_PROJECTOR)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,71 @@
1
+ class ProgressBar
2
+ module Projectors
3
+ class SmoothedAverage
4
+ DEFAULT_STRENGTH = 0.1
5
+ DEFAULT_BEGINNING_POSITION = 0
6
+
7
+ attr_accessor :samples,
8
+ :strength
9
+ attr_reader :projection
10
+
11
+ def initialize(options = {})
12
+ self.samples = []
13
+ self.projection = 0.0
14
+ self.strength = options[:strength] || DEFAULT_STRENGTH
15
+
16
+ start(:at => DEFAULT_BEGINNING_POSITION)
17
+ end
18
+
19
+ def start(options = {})
20
+ self.projection = 0.0
21
+ self.progress = samples[0] = (options[:at] || progress)
22
+ end
23
+
24
+ def decrement
25
+ self.progress -= 1
26
+ end
27
+
28
+ def increment
29
+ self.progress += 1
30
+ end
31
+
32
+ def progress
33
+ samples[1]
34
+ end
35
+
36
+ def total=(_new_total); end
37
+
38
+ def reset
39
+ start(:at => samples[0])
40
+ end
41
+
42
+ def progress=(new_progress)
43
+ samples[1] = new_progress
44
+ self.projection = \
45
+ self.class.calculate(
46
+ @projection,
47
+ absolute,
48
+ strength
49
+ )
50
+ end
51
+
52
+ def none?
53
+ projection.zero?
54
+ end
55
+
56
+ def self.calculate(current_projection, new_value, rate)
57
+ (new_value * (1.0 - rate)) + (current_projection * rate)
58
+ end
59
+
60
+ protected
61
+
62
+ attr_writer :projection
63
+
64
+ private
65
+
66
+ def absolute
67
+ samples[1] - samples[0]
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,3 @@
1
1
  class ProgressBar
2
- VERSION = '1.13.0rc1'.freeze
2
+ VERSION = '1.13.0'.freeze
3
3
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0rc1
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thekompanee
@@ -36,7 +36,7 @@ cert_chain:
36
36
  DV37k4cni6c/jUm2CqepsJ/dbzeWdkhcuO6hwEQV0jvFky5C6d5hHcrbJwxl1sTL
37
37
  V+pWW6L9MSZzKkjWVJXD43B3tWBjIDthQVTzS4j90PUkUXgBXjS7Jxj/
38
38
  -----END CERTIFICATE-----
39
- date: 2023-03-01 00:00:00.000000000 Z
39
+ date: 2023-03-04 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
@@ -109,7 +109,6 @@ files:
109
109
  - lib/progressbar.rb
110
110
  - lib/ruby-progressbar/base.rb
111
111
  - lib/ruby-progressbar/calculators/length.rb
112
- - lib/ruby-progressbar/calculators/smoothed_average.rb
113
112
  - lib/ruby-progressbar/components/bar.rb
114
113
  - lib/ruby-progressbar/components/percentage.rb
115
114
  - lib/ruby-progressbar/components/rate.rb
@@ -124,6 +123,8 @@ files:
124
123
  - lib/ruby-progressbar/outputs/null.rb
125
124
  - lib/ruby-progressbar/outputs/tty.rb
126
125
  - lib/ruby-progressbar/progress.rb
126
+ - lib/ruby-progressbar/projector.rb
127
+ - lib/ruby-progressbar/projectors/smoothed_average.rb
127
128
  - lib/ruby-progressbar/refinements.rb
128
129
  - lib/ruby-progressbar/refinements/progress_enumerator.rb
129
130
  - lib/ruby-progressbar/throttle.rb
@@ -136,7 +137,7 @@ licenses:
136
137
  metadata:
137
138
  bug_tracker_uri: https://github.com/jfelchner/ruby-progressbar/issues
138
139
  changelog_uri: https://github.com/jfelchner/ruby-progressbar/blob/master/CHANGELOG.md
139
- documentation_uri: https://github.com/jfelchner/ruby-progressbar/tree/releases/v1.13.0rc1
140
+ documentation_uri: https://github.com/jfelchner/ruby-progressbar/tree/releases/v1.13.0
140
141
  homepage_uri: https://github.com/jfelchner/ruby-progressbar
141
142
  source_code_uri: https://github.com/jfelchner/ruby-progressbar
142
143
  wiki_uri: https://github.com/jfelchner/ruby-progressbar/wiki
@@ -151,9 +152,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  requirements:
154
- - - ">"
155
+ - - ">="
155
156
  - !ruby/object:Gem::Version
156
- version: 1.3.1
157
+ version: '0'
157
158
  requirements: []
158
159
  rubygems_version: 3.1.6
159
160
  signing_key:
metadata.gz.sig CHANGED
Binary file
@@ -1,9 +0,0 @@
1
- class ProgressBar
2
- module Calculators
3
- class SmoothedAverage
4
- def self.calculate(current_average, new_value_to_average, rate)
5
- (new_value_to_average * (1.0 - rate)) + (current_average * rate)
6
- end
7
- end
8
- end
9
- end