progressbar 1.11.0 → 1.13.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -5
- data/lib/progressbar.rb +0 -10
- data/lib/ruby-progressbar/base.rb +36 -24
- data/lib/ruby-progressbar/calculators/length.rb +0 -2
- data/lib/ruby-progressbar/calculators/smoothed_average.rb +9 -0
- data/lib/ruby-progressbar/components/bar.rb +22 -22
- data/lib/ruby-progressbar/components/percentage.rb +1 -3
- data/lib/ruby-progressbar/components/rate.rb +3 -7
- data/lib/ruby-progressbar/components/time.rb +27 -29
- data/lib/ruby-progressbar/format/formatter.rb +1 -1
- data/lib/ruby-progressbar/format/molecule.rb +21 -20
- data/lib/ruby-progressbar/format/string.rb +2 -0
- data/lib/ruby-progressbar/output.rb +3 -0
- data/lib/ruby-progressbar/progress.rb +21 -9
- data/lib/ruby-progressbar/refinements/progress_enumerator.rb +28 -0
- data/lib/ruby-progressbar/refinements.rb +1 -1
- data/lib/ruby-progressbar/time.rb +3 -5
- data/lib/ruby-progressbar/timer.rb +6 -0
- data/lib/ruby-progressbar/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +30 -30
- metadata.gz.sig +0 -0
- data/lib/ruby-progressbar/calculators/running_average.rb +0 -9
- data/lib/ruby-progressbar/components.rb +0 -5
- data/lib/ruby-progressbar/format.rb +0 -3
- data/lib/ruby-progressbar/refinements/enumerator.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 600c4958d5a0334a7b8c57e026f018d2fbbb16e5dd03b9abc1a989a36b008466
|
4
|
+
data.tar.gz: 895e70eb9b8cc7ca96d86f06e8cc8f6dd36171faa2ea61cd868541b748fdb975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd5be8205221bd7701b32a2174465bab687195e3b764d19c1ccfa1f6a748162eaed3f2259b21f06f8d4a1070c899ef6cfc262f02e6cd7409990b7ac4295fcfe3
|
7
|
+
data.tar.gz: e470d4c737a328d6aad8dbb58796408256b63c4d5efd21ef2e730141cd3ce817b6a4c0d14dec4db2165b6f73d02dcf6ee221f54432a7abd226864dd4416fcd75
|
checksums.yaml.gz.sig
CHANGED
@@ -1,5 +1,2 @@
|
|
1
|
-
��z�+d��-�hJ������-(�y��1�hޤ�ƹ�N�Ţ�O@���q��!���:\�����/s�-#;��g]J�F���O��2�v�
|
2
|
-
������6y��� �'�y�h�;�w�HI��-AEq��BY�+6@w�@�Rn�\=W
|
3
|
-
įȏ�`6�(�9xя�
|
4
|
-
�L���1�N���{�~�J�ѻQ��$J8�Q�ZW���?�q��a�����g�p��t
|
5
|
-
�`�F�?��v��HB7\��~��P#y8X������
|
6
1
|
=4�,��G���SWl�2�*w��|�3�Ho#ܠr����̅���H���T ކ�.�Ǵ��D�;8��yU`�L�볍�����&}{�Ɵ�O��\��.�j��?29��C�:B�FMG���_�tX
|
2
|
+
�d��|���Mwc��Cͭ7;?s�$�u7UFA���.�%O��15�@I5�2�M��e�f�O�s���ǀ)ګ��J>�IgnJ�\x�wHmx
|
3
|
+
Bu�a)Oq�*E��.g'��t?�KAT,���b����H*����u�;�������ow���V�Z3��{��4���3�|���G�.6Y�����}��x}]B�IVJ�� ���,�P�G�J�D.5?��62��0���|b����%��m�pp;��+�ћ_��ly�xδ��;�������8�ZjC�j��ŞWUwR1'��8��s�V��l�AA��v,� A@��B3Ǎc����g��pCD:��:y�v^My��"����ɯxg����C�����-��S[�p����
|
data/lib/progressbar.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ruby-progressbar/output'
|
4
|
-
require 'ruby-progressbar/outputs/tty'
|
5
|
-
require 'ruby-progressbar/outputs/non_tty'
|
6
|
-
require 'ruby-progressbar/timer'
|
7
|
-
require 'ruby-progressbar/progress'
|
8
|
-
require 'ruby-progressbar/throttle'
|
9
|
-
require 'ruby-progressbar/calculators/length'
|
10
|
-
require 'ruby-progressbar/calculators/running_average'
|
11
|
-
require 'ruby-progressbar/components'
|
12
|
-
require 'ruby-progressbar/format'
|
13
3
|
require 'ruby-progressbar/base'
|
14
4
|
require 'ruby-progressbar/refinements' if Module.
|
15
5
|
private_instance_methods.
|
@@ -1,5 +1,17 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
|
+
require 'ruby-progressbar/components/bar'
|
4
|
+
require 'ruby-progressbar/components/percentage'
|
5
|
+
require 'ruby-progressbar/components/rate'
|
6
|
+
require 'ruby-progressbar/components/time'
|
7
|
+
require 'ruby-progressbar/components/title'
|
8
|
+
require 'ruby-progressbar/format/formatter'
|
9
|
+
require 'ruby-progressbar/format/string'
|
10
|
+
require 'ruby-progressbar/outputs/non_tty'
|
11
|
+
require 'ruby-progressbar/outputs/tty'
|
12
|
+
require 'ruby-progressbar/progress'
|
13
|
+
require 'ruby-progressbar/timer'
|
14
|
+
|
3
15
|
class ProgressBar
|
4
16
|
class Base
|
5
17
|
extend Forwardable
|
@@ -21,14 +33,14 @@ class Base
|
|
21
33
|
self.timer = Timer.new(options)
|
22
34
|
self.progressable = Progress.new(options)
|
23
35
|
|
24
|
-
options
|
25
|
-
|
36
|
+
options = options.merge(:progress => progressable,
|
37
|
+
:timer => timer)
|
26
38
|
|
27
|
-
self.
|
28
|
-
self.
|
29
|
-
self.
|
30
|
-
self.
|
31
|
-
self.
|
39
|
+
self.title_component = Components::Title.new(options)
|
40
|
+
self.bar_component = Components::Bar.new(options)
|
41
|
+
self.percentage_component = Components::Percentage.new(options)
|
42
|
+
self.rate_component = Components::Rate.new(options)
|
43
|
+
self.time_component = Components::Time.new(options)
|
32
44
|
|
33
45
|
self.output = Output.detect(options.merge(:bar => self))
|
34
46
|
@format = Format::String.new(output.resolve_format(options[:format]))
|
@@ -102,19 +114,19 @@ class Base
|
|
102
114
|
end
|
103
115
|
|
104
116
|
def progress_mark=(mark)
|
105
|
-
output.refresh_with_format_change {
|
117
|
+
output.refresh_with_format_change { bar_component.progress_mark = mark }
|
106
118
|
end
|
107
119
|
|
108
120
|
def remainder_mark=(mark)
|
109
|
-
output.refresh_with_format_change {
|
121
|
+
output.refresh_with_format_change { bar_component.remainder_mark = mark }
|
110
122
|
end
|
111
123
|
|
112
124
|
def title
|
113
|
-
|
125
|
+
title_component.title
|
114
126
|
end
|
115
127
|
|
116
128
|
def title=(title)
|
117
|
-
output.refresh_with_format_change {
|
129
|
+
output.refresh_with_format_change { title_component.title = title }
|
118
130
|
end
|
119
131
|
|
120
132
|
def to_s(new_format = nil)
|
@@ -128,17 +140,17 @@ class Base
|
|
128
140
|
{
|
129
141
|
'output_stream' => output.__send__(:stream),
|
130
142
|
'length' => output.length,
|
131
|
-
'title' =>
|
132
|
-
'progress_mark' =>
|
133
|
-
'remainder_mark' =>
|
143
|
+
'title' => title_component.title,
|
144
|
+
'progress_mark' => bar_component.progress_mark,
|
145
|
+
'remainder_mark' => bar_component.remainder_mark,
|
134
146
|
'progress' => progressable.progress,
|
135
147
|
'total' => progressable.total,
|
136
148
|
'percentage' => progressable.percentage_completed_with_precision.to_f,
|
137
|
-
'elapsed_time_in_seconds' =>
|
138
|
-
'estimated_time_remaining_in_seconds' =>
|
139
|
-
'base_rate_of_change' =>
|
140
|
-
'scaled_rate_of_change' =>
|
141
|
-
'unknown_progress_animation_steps' =>
|
149
|
+
'elapsed_time_in_seconds' => time_component.__send__(:timer).elapsed_seconds,
|
150
|
+
'estimated_time_remaining_in_seconds' => time_component.__send__(:estimated_seconds_remaining),
|
151
|
+
'base_rate_of_change' => rate_component.__send__(:base_rate),
|
152
|
+
'scaled_rate_of_change' => rate_component.__send__(:scaled_rate),
|
153
|
+
'unknown_progress_animation_steps' => bar_component.upa_steps,
|
142
154
|
'throttle_rate' => output.__send__(:throttle).rate,
|
143
155
|
'started?' => started?,
|
144
156
|
'stopped?' => stopped?,
|
@@ -164,11 +176,11 @@ class Base
|
|
164
176
|
attr_accessor :output,
|
165
177
|
:timer,
|
166
178
|
:progressable,
|
167
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
171
|
-
:
|
179
|
+
:title_component,
|
180
|
+
:bar_component,
|
181
|
+
:percentage_component,
|
182
|
+
:rate_component,
|
183
|
+
:time_component,
|
172
184
|
:autostart,
|
173
185
|
:autofinish,
|
174
186
|
:finished
|
@@ -50,7 +50,6 @@ class Length
|
|
50
50
|
end
|
51
51
|
# rubocop:enable Style/RescueStandardError
|
52
52
|
|
53
|
-
# rubocop:disable Lint/DuplicateMethods
|
54
53
|
begin
|
55
54
|
require 'io/console'
|
56
55
|
|
@@ -68,7 +67,6 @@ class Length
|
|
68
67
|
dynamic_width_via_system_calls
|
69
68
|
end
|
70
69
|
end
|
71
|
-
# rubocop:enable Lint/DuplicateMethods
|
72
70
|
|
73
71
|
def dynamic_width_via_output_stream_object
|
74
72
|
_rows, columns = output.winsize
|
@@ -32,22 +32,6 @@ class Bar
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
private
|
36
|
-
|
37
|
-
def integrated_percentage_complete_string
|
38
|
-
return standard_complete_string if completed_length < 5
|
39
|
-
|
40
|
-
" #{progress.percentage_completed} ".to_s.center(completed_length, progress_mark)
|
41
|
-
end
|
42
|
-
|
43
|
-
def standard_complete_string
|
44
|
-
progress_mark * completed_length
|
45
|
-
end
|
46
|
-
|
47
|
-
def incomplete_string
|
48
|
-
remainder_mark * (length - completed_length)
|
49
|
-
end
|
50
|
-
|
51
35
|
def bar(length)
|
52
36
|
self.length = length
|
53
37
|
|
@@ -66,12 +50,6 @@ class Bar
|
|
66
50
|
to_s(:format => :integrated_percentage)
|
67
51
|
end
|
68
52
|
|
69
|
-
def unknown_string
|
70
|
-
unknown_frame_string = unknown_progress_frame * ((length / upa_steps.size) + 2)
|
71
|
-
|
72
|
-
unknown_frame_string[0, length]
|
73
|
-
end
|
74
|
-
|
75
53
|
def incomplete_space(length)
|
76
54
|
self.length = length
|
77
55
|
|
@@ -88,6 +66,28 @@ class Bar
|
|
88
66
|
integrated_percentage_complete_string
|
89
67
|
end
|
90
68
|
|
69
|
+
private
|
70
|
+
|
71
|
+
def integrated_percentage_complete_string
|
72
|
+
return standard_complete_string if completed_length < 5
|
73
|
+
|
74
|
+
" #{progress.percentage_completed} ".to_s.center(completed_length, progress_mark)
|
75
|
+
end
|
76
|
+
|
77
|
+
def standard_complete_string
|
78
|
+
progress_mark * completed_length
|
79
|
+
end
|
80
|
+
|
81
|
+
def incomplete_string
|
82
|
+
remainder_mark * (length - completed_length)
|
83
|
+
end
|
84
|
+
|
85
|
+
def unknown_string
|
86
|
+
unknown_frame_string = unknown_progress_frame * ((length / upa_steps.size) + 2)
|
87
|
+
|
88
|
+
unknown_frame_string[0, length]
|
89
|
+
end
|
90
|
+
|
91
91
|
def completed_length
|
92
92
|
(length * progress.percentage_completed / 100).floor
|
93
93
|
end
|
@@ -2,23 +2,17 @@ class ProgressBar
|
|
2
2
|
module Components
|
3
3
|
class Rate
|
4
4
|
attr_accessor :rate_scale,
|
5
|
-
:started_at,
|
6
|
-
:stopped_at,
|
7
5
|
:timer,
|
8
6
|
:progress
|
9
7
|
|
10
8
|
def initialize(options = {})
|
11
9
|
self.rate_scale = options[:rate_scale] || lambda { |x| x }
|
12
|
-
self.started_at = nil
|
13
|
-
self.stopped_at = nil
|
14
10
|
self.timer = options[:timer]
|
15
11
|
self.progress = options[:progress]
|
16
12
|
end
|
17
13
|
|
18
|
-
private
|
19
|
-
|
20
14
|
def rate_of_change(format_string = '%i')
|
21
|
-
return 0
|
15
|
+
return '0' if elapsed_seconds <= 0
|
22
16
|
|
23
17
|
format_string % scaled_rate
|
24
18
|
end
|
@@ -27,6 +21,8 @@ class Rate
|
|
27
21
|
rate_of_change('%.2f')
|
28
22
|
end
|
29
23
|
|
24
|
+
private
|
25
|
+
|
30
26
|
def scaled_rate
|
31
27
|
rate_scale.call(base_rate)
|
32
28
|
end
|
@@ -12,60 +12,56 @@ class Time
|
|
12
12
|
NO_TIME_ELAPSED_TEXT = '--:--:--'.freeze
|
13
13
|
ESTIMATED_LABEL = ' ETA'.freeze
|
14
14
|
ELAPSED_LABEL = 'Time'.freeze
|
15
|
+
WALL_CLOCK_FORMAT = '%H:%M:%S'.freeze
|
15
16
|
OOB_TEXT_TO_FORMAT = {
|
16
17
|
:unknown => OOB_UNKNOWN_TIME_TEXT,
|
17
18
|
:friendly => OOB_FRIENDLY_TIME_TEXT
|
18
19
|
}.freeze
|
19
20
|
|
20
21
|
def initialize(options = {})
|
21
|
-
self.
|
22
|
-
self.
|
23
|
-
self.progress = options[:progress]
|
22
|
+
self.timer = options[:timer]
|
23
|
+
self.progress = options[:progress]
|
24
24
|
end
|
25
25
|
|
26
|
-
def estimated_with_label
|
27
|
-
"#{ESTIMATED_LABEL}: #{estimated}"
|
26
|
+
def estimated_with_label(out_of_bounds_time_format = nil)
|
27
|
+
"#{ESTIMATED_LABEL}: #{estimated(out_of_bounds_time_format)}"
|
28
28
|
end
|
29
29
|
|
30
30
|
def elapsed_with_label
|
31
31
|
"#{ELAPSED_LABEL}: #{elapsed}"
|
32
32
|
end
|
33
33
|
|
34
|
-
protected
|
35
|
-
|
36
34
|
def estimated_with_no_oob
|
37
|
-
|
38
|
-
|
39
|
-
estimated_with_elapsed_fallback
|
35
|
+
estimated_with_elapsed_fallback(nil)
|
40
36
|
end
|
41
37
|
|
42
38
|
def estimated_with_unknown_oob
|
43
|
-
|
44
|
-
|
45
|
-
estimated_with_elapsed_fallback
|
39
|
+
estimated_with_elapsed_fallback(:unknown)
|
46
40
|
end
|
47
41
|
|
48
42
|
def estimated_with_friendly_oob
|
49
|
-
|
50
|
-
|
51
|
-
estimated_with_elapsed_fallback
|
43
|
+
estimated_with_elapsed_fallback(:friendly)
|
52
44
|
end
|
53
45
|
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
def estimated_wall_clock
|
47
|
+
return timer.stopped_at.strftime(WALL_CLOCK_FORMAT) if progress.finished?
|
48
|
+
return NO_TIME_ELAPSED_TEXT unless timer.started?
|
57
49
|
|
58
|
-
|
59
|
-
unless
|
60
|
-
fail StandardError, "Invalid Out Of Bounds time format. Valid formats are #{OOB_TIME_FORMATS.inspect}"
|
61
|
-
end
|
50
|
+
memo_estimated_seconds_remaining = estimated_seconds_remaining
|
51
|
+
return NO_TIME_ELAPSED_TEXT unless memo_estimated_seconds_remaining
|
62
52
|
|
63
|
-
|
53
|
+
(timer.now + memo_estimated_seconds_remaining).
|
54
|
+
strftime(WALL_CLOCK_FORMAT)
|
64
55
|
end
|
65
56
|
|
57
|
+
protected
|
58
|
+
|
59
|
+
attr_accessor :timer,
|
60
|
+
:progress
|
61
|
+
|
66
62
|
private
|
67
63
|
|
68
|
-
def estimated
|
64
|
+
def estimated(out_of_bounds_time_format)
|
69
65
|
memo_estimated_seconds_remaining = estimated_seconds_remaining
|
70
66
|
|
71
67
|
return OOB_UNKNOWN_TIME_TEXT unless memo_estimated_seconds_remaining
|
@@ -73,7 +69,7 @@ class Time
|
|
73
69
|
hours, minutes, seconds = timer.divide_seconds(memo_estimated_seconds_remaining)
|
74
70
|
|
75
71
|
if hours > OOB_LIMIT_IN_HOURS && out_of_bounds_time_format
|
76
|
-
OOB_TEXT_TO_FORMAT
|
72
|
+
OOB_TEXT_TO_FORMAT.fetch(out_of_bounds_time_format)
|
77
73
|
else
|
78
74
|
TIME_FORMAT % [hours, minutes, seconds]
|
79
75
|
end
|
@@ -87,14 +83,16 @@ class Time
|
|
87
83
|
TIME_FORMAT % [hours, minutes, seconds]
|
88
84
|
end
|
89
85
|
|
90
|
-
def estimated_with_elapsed_fallback
|
91
|
-
progress.finished?
|
86
|
+
def estimated_with_elapsed_fallback(out_of_bounds_time_format)
|
87
|
+
return elapsed_with_label if progress.finished?
|
88
|
+
|
89
|
+
estimated_with_label(out_of_bounds_time_format)
|
92
90
|
end
|
93
91
|
|
94
92
|
def estimated_seconds_remaining
|
95
93
|
return if progress.unknown? || progress.none? || timer.stopped? || timer.reset?
|
96
94
|
|
97
|
-
(timer.elapsed_seconds * (progress.total / progress.running_average - 1)).round
|
95
|
+
(timer.elapsed_seconds * ((progress.total / progress.running_average) - 1)).round
|
98
96
|
end
|
99
97
|
end
|
100
98
|
end
|
@@ -13,7 +13,7 @@ class Formatter
|
|
13
13
|
bar_length = max_length -
|
14
14
|
processed_string.displayable_length +
|
15
15
|
format_string.bar_molecule_placeholder_length
|
16
|
-
bar_length =
|
16
|
+
bar_length = 0 if bar_length < 0
|
17
17
|
|
18
18
|
format_string.bar_molecules.each do |molecule|
|
19
19
|
processed_string.gsub!(molecule.full_key,
|
@@ -2,26 +2,27 @@ class ProgressBar
|
|
2
2
|
module Format
|
3
3
|
class Molecule
|
4
4
|
MOLECULES = {
|
5
|
-
:t => [:
|
6
|
-
:T => [:
|
7
|
-
:c => [:progressable,
|
8
|
-
:C => [:progressable,
|
9
|
-
:u => [:progressable,
|
10
|
-
:p => [:
|
11
|
-
:P => [:
|
12
|
-
:j => [:
|
13
|
-
:J => [:
|
14
|
-
:a => [:
|
15
|
-
:e => [:
|
16
|
-
:E => [:
|
17
|
-
:f => [:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
5
|
+
:t => [:title_component, :title],
|
6
|
+
:T => [:title_component, :title],
|
7
|
+
:c => [:progressable, :progress],
|
8
|
+
:C => [:progressable, :total],
|
9
|
+
:u => [:progressable, :total_with_unknown_indicator],
|
10
|
+
:p => [:percentage_component, :percentage],
|
11
|
+
:P => [:percentage_component, :percentage_with_precision],
|
12
|
+
:j => [:percentage_component, :justified_percentage],
|
13
|
+
:J => [:percentage_component, :justified_percentage_with_precision],
|
14
|
+
:a => [:time_component, :elapsed_with_label],
|
15
|
+
:e => [:time_component, :estimated_with_unknown_oob],
|
16
|
+
:E => [:time_component, :estimated_with_friendly_oob],
|
17
|
+
:f => [:time_component, :estimated_with_no_oob],
|
18
|
+
:l => [:time_component, :estimated_wall_clock],
|
19
|
+
:B => [:bar_component, :complete_bar],
|
20
|
+
:b => [:bar_component, :bar],
|
21
|
+
:W => [:bar_component, :complete_bar_with_percentage],
|
22
|
+
:w => [:bar_component, :bar_with_percentage],
|
23
|
+
:i => [:bar_component, :incomplete_space],
|
24
|
+
:r => [:rate_component, :rate_of_change],
|
25
|
+
:R => [:rate_component, :rate_of_change_with_precision]
|
25
26
|
}.freeze
|
26
27
|
|
27
28
|
BAR_MOLECULES = %w{W w B b i}.freeze
|
@@ -1,21 +1,33 @@
|
|
1
1
|
require 'ruby-progressbar/errors/invalid_progress_error'
|
2
|
+
require 'ruby-progressbar/calculators/smoothed_average'
|
2
3
|
|
3
4
|
class ProgressBar
|
4
5
|
class Progress
|
5
|
-
DEFAULT_TOTAL
|
6
|
-
DEFAULT_BEGINNING_POSITION
|
7
|
-
|
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
|
8
14
|
|
9
15
|
attr_reader :total,
|
10
16
|
:progress
|
11
17
|
|
12
18
|
attr_accessor :starting_position,
|
13
19
|
:running_average,
|
14
|
-
:
|
20
|
+
:running_average_calculator,
|
21
|
+
:running_average_rate
|
15
22
|
|
16
23
|
def initialize(options = {})
|
17
|
-
self.total
|
18
|
-
self.
|
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)
|
19
31
|
|
20
32
|
start :at => DEFAULT_BEGINNING_POSITION
|
21
33
|
end
|
@@ -66,9 +78,9 @@ class Progress
|
|
66
78
|
|
67
79
|
@progress = new_progress
|
68
80
|
|
69
|
-
self.running_average =
|
70
|
-
|
71
|
-
|
81
|
+
self.running_average = running_average_calculator.calculate(running_average,
|
82
|
+
absolute,
|
83
|
+
running_average_rate)
|
72
84
|
end
|
73
85
|
|
74
86
|
def total=(new_total)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class ProgressBar
|
2
|
+
module Refinements
|
3
|
+
module Enumerator
|
4
|
+
ARITY_ERROR_MESSAGE = 'Only two arguments allowed to be passed to ' \
|
5
|
+
'with_progressbar (item, progress_bar)'.freeze
|
6
|
+
|
7
|
+
refine ::Enumerator do
|
8
|
+
def with_progressbar(options = {}, &block)
|
9
|
+
progress_bar = ProgressBar.create(options.merge(:starting_at => 0, :total => size))
|
10
|
+
|
11
|
+
each do |item|
|
12
|
+
progress_bar.increment
|
13
|
+
|
14
|
+
next unless block
|
15
|
+
|
16
|
+
yielded_args = []
|
17
|
+
yielded_args << item if block.arity > 0
|
18
|
+
yielded_args << progress_bar if block.arity > 1
|
19
|
+
|
20
|
+
fail ::ArgumentError, ARITY_ERROR_MESSAGE if block.arity > 2
|
21
|
+
|
22
|
+
yield(*yielded_args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
require 'ruby-progressbar/refinements/
|
1
|
+
require 'ruby-progressbar/refinements/progress_enumerator'
|
@@ -17,11 +17,9 @@ class Time
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def unmocked_time_method
|
20
|
-
@unmocked_time_method ||=
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
20
|
+
@unmocked_time_method ||= TIME_MOCKING_LIBRARY_METHODS.find do |method|
|
21
|
+
time.respond_to? method
|
22
|
+
end
|
25
23
|
end
|
26
24
|
|
27
25
|
protected
|
@@ -28,6 +28,10 @@ class Timer
|
|
28
28
|
start
|
29
29
|
end
|
30
30
|
|
31
|
+
def now
|
32
|
+
time.now
|
33
|
+
end
|
34
|
+
|
31
35
|
def started?
|
32
36
|
started_at
|
33
37
|
end
|
@@ -51,6 +55,8 @@ class Timer
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def elapsed_seconds
|
58
|
+
return 0 unless started?
|
59
|
+
|
54
60
|
((stopped_at || time.now) - started_at)
|
55
61
|
end
|
56
62
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progressbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.13.0rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thekompanee
|
8
8
|
- jfelchner
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
12
|
- |
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
MIIEdjCCAt6gAwIBAgIBATANBgkqhkiG9w0BAQsFADAyMTAwLgYDVQQDDCdhY2Nv
|
15
|
+
dW50c19ydWJ5Z2Vtcy9EQz10aGVrb21wYW5lZS9EQz1jb20wHhcNMjMwMjI2MTcx
|
16
|
+
MDI1WhcNMjYwMjI1MTcxMDI1WjAyMTAwLgYDVQQDDCdhY2NvdW50c19ydWJ5Z2Vt
|
17
17
|
cy9EQz10aGVrb21wYW5lZS9EQz1jb20wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAw
|
18
18
|
ggGKAoIBgQCqhYn5ODEoLvuBIF2M1GzoaZU28+ntP5QApvDE0Te04n0JbBC1cNYH
|
19
19
|
mr71neeSx7tlZ9w9kJ/8GNcY5bm7pNJqhyhfc+uG9M7FttcxM8AYXogjcdUDP234
|
@@ -23,18 +23,20 @@ cert_chain:
|
|
23
23
|
ztMEU785tERbOSszZrz9rBS/+GnMxlD0pxy50zFfHX3jY1hwnwGjE8Gg+0iYr/tm
|
24
24
|
eysjhcbZfKrMynoqAioCSwstIwtYYYYpYzCPZzwaIBaBqQmUTkuMeiGbAdOdFOrR
|
25
25
|
lOgl5jxCYbNOOTaXbm0nGBFaTucB88+JLbsNAuoNGUf/ybDcZ1zKRkMr2vtb+OtL
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
GoP81fN6l88CAwEAAaOBljCBkzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
|
27
|
+
HQ4EFgQUL4eV4OM9h7fkM27qf9p4ragHi6AwLAYDVR0RBCUwI4EhYWNjb3VudHMr
|
28
|
+
cnVieWdlbXNAdGhla29tcGFuZWUuY29tMCwGA1UdEgQlMCOBIWFjY291bnRzK3J1
|
29
|
+
YnlnZW1zQHRoZWtvbXBhbmVlLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAD/tBN1cM
|
30
|
+
8Qu6u+rPM3SEtlEK/ZdVY0IowXtXMskkderNBJ4HY+xBfIWyAXLTr3Fy6xscVZ95
|
31
|
+
raFCiWHqvR577u3/BsVZ5BoQ0g25oY2bwoamQSdx71ygs25Q+UFbg6lHq6olszj0
|
32
|
+
HqKXUy/iPFb+OzGq7NOtKOD5pHl3ew8H7U5tfh0kx6B5TdL9BZLurjskW0n2G+kY
|
33
|
+
NSGCTGYU8wY4Bsk/AmfoFT/ATwmrf68CTD+IBY5yvt2DGvcyuSrX1RQP8Vk//0EP
|
34
|
+
J2ezTNGIBeQFcyyo09gMfy1yxv9XAvwmy6pAx7/m/F2XzTiXuzmJ7zJ6J0OaHUG4
|
35
|
+
svJgf3o9Eor2okQND60Qdpdl4qdSy3KaNqvQQbTRB96e/+K8ksz4rras5jPaAs0p
|
36
|
+
DV37k4cni6c/jUm2CqepsJ/dbzeWdkhcuO6hwEQV0jvFky5C6d5hHcrbJwxl1sTL
|
37
|
+
V+pWW6L9MSZzKkjWVJXD43B3tWBjIDthQVTzS4j90PUkUXgBXjS7Jxj/
|
36
38
|
-----END CERTIFICATE-----
|
37
|
-
date:
|
39
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
38
40
|
dependencies:
|
39
41
|
- !ruby/object:Gem::Dependency
|
40
42
|
name: rspec
|
@@ -82,16 +84,16 @@ dependencies:
|
|
82
84
|
name: timecop
|
83
85
|
requirement: !ruby/object:Gem::Requirement
|
84
86
|
requirements:
|
85
|
-
- -
|
87
|
+
- - "~>"
|
86
88
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0.
|
89
|
+
version: '0.9'
|
88
90
|
type: :development
|
89
91
|
prerelease: false
|
90
92
|
version_requirements: !ruby/object:Gem::Requirement
|
91
93
|
requirements:
|
92
|
-
- -
|
94
|
+
- - "~>"
|
93
95
|
- !ruby/object:Gem::Version
|
94
|
-
version: 0.
|
96
|
+
version: '0.9'
|
95
97
|
description: 'Ruby/ProgressBar is an extremely flexible text progress bar library
|
96
98
|
for Ruby. The output can be customized with a flexible formatting system including:
|
97
99
|
percentage, bars of various formats, elapsed time and estimated time remaining.'
|
@@ -107,15 +109,13 @@ files:
|
|
107
109
|
- lib/progressbar.rb
|
108
110
|
- lib/ruby-progressbar/base.rb
|
109
111
|
- lib/ruby-progressbar/calculators/length.rb
|
110
|
-
- lib/ruby-progressbar/calculators/
|
111
|
-
- lib/ruby-progressbar/components.rb
|
112
|
+
- lib/ruby-progressbar/calculators/smoothed_average.rb
|
112
113
|
- lib/ruby-progressbar/components/bar.rb
|
113
114
|
- lib/ruby-progressbar/components/percentage.rb
|
114
115
|
- lib/ruby-progressbar/components/rate.rb
|
115
116
|
- lib/ruby-progressbar/components/time.rb
|
116
117
|
- lib/ruby-progressbar/components/title.rb
|
117
118
|
- lib/ruby-progressbar/errors/invalid_progress_error.rb
|
118
|
-
- lib/ruby-progressbar/format.rb
|
119
119
|
- lib/ruby-progressbar/format/formatter.rb
|
120
120
|
- lib/ruby-progressbar/format/molecule.rb
|
121
121
|
- lib/ruby-progressbar/format/string.rb
|
@@ -125,7 +125,7 @@ files:
|
|
125
125
|
- lib/ruby-progressbar/outputs/tty.rb
|
126
126
|
- lib/ruby-progressbar/progress.rb
|
127
127
|
- lib/ruby-progressbar/refinements.rb
|
128
|
-
- lib/ruby-progressbar/refinements/
|
128
|
+
- lib/ruby-progressbar/refinements/progress_enumerator.rb
|
129
129
|
- lib/ruby-progressbar/throttle.rb
|
130
130
|
- lib/ruby-progressbar/time.rb
|
131
131
|
- lib/ruby-progressbar/timer.rb
|
@@ -136,11 +136,11 @@ licenses:
|
|
136
136
|
metadata:
|
137
137
|
bug_tracker_uri: https://github.com/jfelchner/ruby-progressbar/issues
|
138
138
|
changelog_uri: https://github.com/jfelchner/ruby-progressbar/blob/master/CHANGELOG.md
|
139
|
-
documentation_uri: https://github.com/jfelchner/ruby-progressbar/tree/releases/v1.
|
139
|
+
documentation_uri: https://github.com/jfelchner/ruby-progressbar/tree/releases/v1.13.0rc1
|
140
140
|
homepage_uri: https://github.com/jfelchner/ruby-progressbar
|
141
141
|
source_code_uri: https://github.com/jfelchner/ruby-progressbar
|
142
142
|
wiki_uri: https://github.com/jfelchner/ruby-progressbar/wiki
|
143
|
-
post_install_message:
|
143
|
+
post_install_message:
|
144
144
|
rdoc_options: []
|
145
145
|
require_paths:
|
146
146
|
- lib
|
@@ -151,12 +151,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
151
|
version: '0'
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
|
-
- - "
|
154
|
+
- - ">"
|
155
155
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
156
|
+
version: 1.3.1
|
157
157
|
requirements: []
|
158
|
-
rubygems_version: 3.
|
159
|
-
signing_key:
|
158
|
+
rubygems_version: 3.1.6
|
159
|
+
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Ruby/ProgressBar is a flexible text progress bar library for Ruby.
|
162
162
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class ProgressBar
|
2
|
-
module Refinements
|
3
|
-
module Enumerator
|
4
|
-
refine ::Enumerator do
|
5
|
-
def with_progressbar(options = {}, &block)
|
6
|
-
chain = ::Enumerator.new do |yielder|
|
7
|
-
progress_bar = ProgressBar.create(options.merge(:starting_at => 0, :total => size))
|
8
|
-
|
9
|
-
each do |*args|
|
10
|
-
yielder.yield(*args).tap do
|
11
|
-
progress_bar.increment
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
return chain unless block
|
17
|
-
|
18
|
-
chain.each(&block)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|