progressbar 1.10.1 → 1.12.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.txt +1 -1
- data/README.md +110 -17
- data/lib/progressbar.rb +0 -10
- data/lib/ruby-progressbar/base.rb +39 -27
- 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 +32 -40
- 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 +3 -1
- data/lib/ruby-progressbar/output.rb +3 -0
- data/lib/ruby-progressbar/outputs/tty.rb +1 -1
- data/lib/ruby-progressbar/progress.rb +21 -9
- data/lib/ruby-progressbar/refinements/enumerator.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 +19 -35
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fed7ad39c43e9cf2fc85b87d1ffa94981e94e7e796ab8526f1357be3e186eab2
|
4
|
+
data.tar.gz: 91f458a9dc472ffad2bc83bcc5c9d65902c90dc9a4cf4587da51bcdd5874f37c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c708755ac0db269805376f4f4285377b24cbbc78e765a9ef7f83fe469bc9f85cdd552c4d62f76fc4005e70b8e7b5e4517aa945fcd0adbeedef1d93c983baff2
|
7
|
+
data.tar.gz: a9d7ebd15e82250a46cf6dd8c41c88e239aa5fbf43c1544b6f629aa3b383c28f3984aba1ff3b7b3d255058237bce401a7092f1b1ac026b04d8a832ad2063c819
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,131 @@
|
|
1
1
|
Ruby/ProgressBar
|
2
|
-
|
3
|
-
|
2
|
+
================================================================================
|
3
|
+
|
4
|
+
<div align="center">
|
5
|
+
<a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Version">
|
6
|
+
<img src="https://img.shields.io/gem/v/ruby-progressbar.svg?style=flat-square&label=current-version" alt="RubyGems Version" />
|
7
|
+
</a>
|
8
|
+
|
9
|
+
<a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Rank Overall">
|
10
|
+
<img src="https://img.shields.io/gem/rt/ruby-progressbar.svg?style=flat-square&label=total-rank" alt="RubyGems Rank Overall" />
|
11
|
+
</a>
|
12
|
+
|
13
|
+
<a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Rank Daily">
|
14
|
+
<img src="https://img.shields.io/gem/rd/ruby-progressbar.svg?style=flat-square&label=daily-rank" alt="RubyGems Rank Daily" />
|
15
|
+
</a>
|
16
|
+
|
17
|
+
<a href="https://rubygems.org/gems/ruby-progressbar" alt="RubyGems Downloads">
|
18
|
+
<img src="https://img.shields.io/gem/dt/ruby-progressbar.svg?style=flat-square&label=total-downloads" alt="RubyGems Downloads" />
|
19
|
+
</a>
|
20
|
+
|
21
|
+
<a href="https://github.com/jfelchner/ruby-progressbar/actions?query=workflow%3ABuild" alt="Build Status">
|
22
|
+
<img src="https://img.shields.io/github/workflow/status/jfelchner/ruby-progressbar/Build?label=CI&style=flat-square&logo=github" alt="Build Status" />
|
23
|
+
</a>
|
24
|
+
|
25
|
+
<a href="#" alt="Maintainability">
|
26
|
+
<img src="https://img.shields.io/codeclimate/maintainability/jfelchner/ruby-progressbar?style=flat-square&label=grade" alt="Maintainability" />
|
27
|
+
</a>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<br>
|
4
31
|
|
5
32
|
<img src="https://kompanee-public-assets.s3.amazonaws.com/readmes/ruby-progressbar-cage.png" align="right" />
|
6
33
|
|
7
|
-
The **ultimate** text progress bar library for Ruby! It'll **SMASH YOU OVER THE
|
34
|
+
The **ultimate** text progress bar library for Ruby! It'll **SMASH YOU OVER THE
|
35
|
+
HEAD** with a **PURE RUSH** of progress bar excitement!
|
8
36
|
|
9
|
-
Don't miss out on what all the kids are talking about! If you want everyone to
|
37
|
+
Don't miss out on what all the kids are talking about! If you want everyone to
|
38
|
+
know that your gem or app can survive _in the cage_ then YOU WANT
|
39
|
+
**RUBY-PROGRESSBAR**!
|
10
40
|
|
11
|
-
<br
|
41
|
+
<br>
|
12
42
|
|
13
|
-
|
14
|
-
|
43
|
+
It's Better Than The Other 186,312 Progress Bar Libraries Because
|
44
|
+
--------------------------------------------------------------------------------
|
45
|
+
|
46
|
+
* It has [stood the test of time][history] (2008-today)
|
47
|
+
|
48
|
+
* Full test suite
|
49
|
+
|
50
|
+
* [_**ZERO**_ dependencies][gemspec]
|
51
|
+
|
52
|
+
* Used by [tons of other open source projects][dependencies] (which means we
|
53
|
+
find out about bugs quickly)
|
54
|
+
|
55
|
+
* It's pretty [freakin' sweet](https://www.youtube.com/watch?v=On3IoVhf_GM)
|
56
|
+
|
57
|
+
* And most importantly... our awesome [contributors][contributors]
|
58
|
+
|
59
|
+
Basic Usage
|
60
|
+
--------------------------------------------------------------------------------
|
15
61
|
|
16
|
-
|
62
|
+
### Creation
|
17
63
|
|
18
|
-
|
64
|
+
It's simple to get started:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
progressbar = ProgressBar.create
|
68
|
+
```
|
69
|
+
|
70
|
+
Creates a basic progress bar beginning at `0`, a maximum capacity of `100` and
|
71
|
+
tells it to start.
|
72
|
+
|
73
|
+
```text
|
74
|
+
Progress: | |
|
75
|
+
```
|
76
|
+
|
77
|
+
### Marking Progress
|
78
|
+
|
79
|
+
Every call to `#increment` will advance the bar by `1`. Therefore:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
50.times { progressbar.increment }
|
83
|
+
```
|
84
|
+
|
85
|
+
Would output an advancing line which would end up here:
|
86
|
+
|
87
|
+
```text
|
88
|
+
Progress: |=================================== |
|
89
|
+
```
|
90
|
+
|
91
|
+
### Animation
|
92
|
+
|
93
|
+

|
94
|
+
|
95
|
+
Full Reference
|
96
|
+
--------------------------------------------------------------------------------
|
97
|
+
|
98
|
+
There's gotten to be too much awesome to pack into one page. Visit the
|
99
|
+
[wiki][wiki] for the full documentation.
|
19
100
|
|
20
101
|
Issues
|
21
|
-
|
102
|
+
--------------------------------------------------------------------------------
|
22
103
|
|
23
|
-
If you have problems, please create a [Github issue]
|
104
|
+
If you have problems, please create a [Github issue][issues].
|
24
105
|
|
25
106
|
Credits
|
26
|
-
|
107
|
+
--------------------------------------------------------------------------------
|
27
108
|
|
28
|
-
![The Kompanee]
|
109
|
+
![The Kompanee][kompanee-logo]
|
29
110
|
|
30
|
-
ruby-progressbar is maintained by [The Kompanee, Ltd.]
|
111
|
+
ruby-progressbar is maintained by [The Kompanee, Ltd.][kompanee-site]
|
31
112
|
|
32
113
|
The names and logos for The Kompanee are trademarks of The Kompanee, Ltd.
|
33
114
|
|
34
115
|
License
|
35
|
-
|
116
|
+
--------------------------------------------------------------------------------
|
117
|
+
|
118
|
+
ruby-progressbar 1.0 is Copyright © 2011-2021 The Kompanee. It is free
|
119
|
+
software, and may be redistributed under the terms specified in the LICENSE
|
120
|
+
file.
|
121
|
+
ruby-progressbar 0.9.0 is Copyright © 2008 [Satoru Takabayashi][satoru]
|
36
122
|
|
37
|
-
ruby-progressbar
|
38
|
-
|
123
|
+
[contributors]: https://github.com/jfelchner/ruby-progressbar/graphs/contributors
|
124
|
+
[dependencies]: https://github.com/jfelchner/ruby-progressbar/network/dependents
|
125
|
+
[gemspec]: https://github.com/jfelchner/ruby-progressbar/blob/master/ruby-progressbar.gemspec
|
126
|
+
[history]: https://github.com/jfelchner/ruby-progressbar/wiki/History
|
127
|
+
[issues]: https://github.com/jfelchner/ruby-progressbar/issues
|
128
|
+
[kompanee-logo]: https://kompanee-public-assets.s3.amazonaws.com/readmes/kompanee-horizontal-black.png
|
129
|
+
[kompanee-site]: http://www.thekompanee.com
|
130
|
+
[satoru]: http://0xcc.net
|
131
|
+
[wiki]: https://github.com/jfelchner/ruby-progressbar/wiki
|
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
|
@@ -13,7 +25,7 @@ class Base
|
|
13
25
|
:progress,
|
14
26
|
:total
|
15
27
|
|
16
|
-
def initialize(options = {})
|
28
|
+
def initialize(options = {}) # rubocop:disable Metrics/AbcSize
|
17
29
|
self.autostart = options.fetch(:autostart, true)
|
18
30
|
self.autofinish = options.fetch(:autofinish, true)
|
19
31
|
self.finished = false
|
@@ -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)
|
@@ -123,29 +135,29 @@ class Base
|
|
123
135
|
Format::Formatter.process(@format, output.length, self)
|
124
136
|
end
|
125
137
|
|
126
|
-
# rubocop:disable Metrics/AbcSize,
|
138
|
+
# rubocop:disable Metrics/AbcSize, Layout/LineLength
|
127
139
|
def to_h
|
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?,
|
145
157
|
'finished?' => finished?
|
146
158
|
}
|
147
159
|
end
|
148
|
-
# rubocop:enable Metrics/AbcSize,
|
160
|
+
# rubocop:enable Metrics/AbcSize, Layout/LineLength
|
149
161
|
|
150
162
|
def inspect
|
151
163
|
"#<ProgressBar:#{progress}/#{total || 'unknown'}>"
|
@@ -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,57 +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
|
16
|
+
OOB_TEXT_TO_FORMAT = {
|
17
|
+
:unknown => OOB_UNKNOWN_TIME_TEXT,
|
18
|
+
:friendly => OOB_FRIENDLY_TIME_TEXT
|
19
|
+
}.freeze
|
15
20
|
|
16
21
|
def initialize(options = {})
|
17
|
-
self.
|
18
|
-
self.
|
19
|
-
self.progress = options[:progress]
|
22
|
+
self.timer = options[:timer]
|
23
|
+
self.progress = options[:progress]
|
20
24
|
end
|
21
25
|
|
22
|
-
def estimated_with_label
|
23
|
-
"#{ESTIMATED_LABEL}: #{estimated}"
|
26
|
+
def estimated_with_label(out_of_bounds_time_format = nil)
|
27
|
+
"#{ESTIMATED_LABEL}: #{estimated(out_of_bounds_time_format)}"
|
24
28
|
end
|
25
29
|
|
26
30
|
def elapsed_with_label
|
27
31
|
"#{ELAPSED_LABEL}: #{elapsed}"
|
28
32
|
end
|
29
33
|
|
30
|
-
protected
|
31
|
-
|
32
34
|
def estimated_with_no_oob
|
33
|
-
|
34
|
-
|
35
|
-
estimated_with_elapsed_fallback
|
35
|
+
estimated_with_elapsed_fallback(nil)
|
36
36
|
end
|
37
37
|
|
38
38
|
def estimated_with_unknown_oob
|
39
|
-
|
40
|
-
|
41
|
-
estimated_with_elapsed_fallback
|
39
|
+
estimated_with_elapsed_fallback(:unknown)
|
42
40
|
end
|
43
41
|
|
44
42
|
def estimated_with_friendly_oob
|
45
|
-
|
46
|
-
|
47
|
-
estimated_with_elapsed_fallback
|
43
|
+
estimated_with_elapsed_fallback(:friendly)
|
48
44
|
end
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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?
|
53
49
|
|
54
|
-
|
55
|
-
unless
|
56
|
-
fail 'Invalid Out Of Bounds time format. Valid formats are ' +
|
57
|
-
OOB_TIME_FORMATS.inspect
|
58
|
-
end
|
50
|
+
memo_estimated_seconds_remaining = estimated_seconds_remaining
|
51
|
+
return NO_TIME_ELAPSED_TEXT unless memo_estimated_seconds_remaining
|
59
52
|
|
60
|
-
|
53
|
+
(timer.now + memo_estimated_seconds_remaining).
|
54
|
+
strftime(WALL_CLOCK_FORMAT)
|
61
55
|
end
|
62
56
|
|
57
|
+
protected
|
58
|
+
|
59
|
+
attr_accessor :timer,
|
60
|
+
:progress
|
61
|
+
|
63
62
|
private
|
64
63
|
|
65
|
-
def estimated
|
64
|
+
def estimated(out_of_bounds_time_format)
|
66
65
|
memo_estimated_seconds_remaining = estimated_seconds_remaining
|
67
66
|
|
68
67
|
return OOB_UNKNOWN_TIME_TEXT unless memo_estimated_seconds_remaining
|
@@ -70,7 +69,7 @@ class Time
|
|
70
69
|
hours, minutes, seconds = timer.divide_seconds(memo_estimated_seconds_remaining)
|
71
70
|
|
72
71
|
if hours > OOB_LIMIT_IN_HOURS && out_of_bounds_time_format
|
73
|
-
|
72
|
+
OOB_TEXT_TO_FORMAT.fetch(out_of_bounds_time_format)
|
74
73
|
else
|
75
74
|
TIME_FORMAT % [hours, minutes, seconds]
|
76
75
|
end
|
@@ -84,23 +83,16 @@ class Time
|
|
84
83
|
TIME_FORMAT % [hours, minutes, seconds]
|
85
84
|
end
|
86
85
|
|
87
|
-
def estimated_with_elapsed_fallback
|
88
|
-
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)
|
89
90
|
end
|
90
91
|
|
91
92
|
def estimated_seconds_remaining
|
92
|
-
return if progress.unknown? || progress.none? || timer.stopped?
|
93
|
-
|
94
|
-
(timer.elapsed_seconds * (progress.total / progress.running_average - 1)).round
|
95
|
-
end
|
93
|
+
return if progress.unknown? || progress.none? || timer.stopped? || timer.reset?
|
96
94
|
|
97
|
-
|
98
|
-
case out_of_bounds_time_format
|
99
|
-
when :unknown
|
100
|
-
OOB_UNKNOWN_TIME_TEXT
|
101
|
-
when :friendly
|
102
|
-
OOB_FRIENDLY_TIME_TEXT
|
103
|
-
end
|
95
|
+
(timer.elapsed_seconds * ((progress.total / progress.running_average) - 1)).round
|
104
96
|
end
|
105
97
|
end
|
106
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)
|
@@ -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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progressbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thekompanee
|
@@ -12,8 +12,8 @@ cert_chain:
|
|
12
12
|
- |
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
14
|
MIIEdjCCAt6gAwIBAgIBATANBgkqhkiG9w0BAQsFADAyMTAwLgYDVQQDDCdhY2Nv
|
15
|
-
|
16
|
-
|
15
|
+
dW50c19ydWJ5Z2Vtcy9EQz10aGVrb21wYW5lZS9EQz1jb20wHhcNMjMwMjI2MTcx
|
16
|
+
MDI1WhcNMjYwMjI1MTcxMDI1WjAyMTAwLgYDVQQDDCdhY2NvdW50c19ydWJ5Z2Vt
|
17
17
|
cy9EQz10aGVrb21wYW5lZS9EQz1jb20wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAw
|
18
18
|
ggGKAoIBgQCqhYn5ODEoLvuBIF2M1GzoaZU28+ntP5QApvDE0Te04n0JbBC1cNYH
|
19
19
|
mr71neeSx7tlZ9w9kJ/8GNcY5bm7pNJqhyhfc+uG9M7FttcxM8AYXogjcdUDP234
|
@@ -26,17 +26,17 @@ cert_chain:
|
|
26
26
|
GoP81fN6l88CAwEAAaOBljCBkzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
|
27
27
|
HQ4EFgQUL4eV4OM9h7fkM27qf9p4ragHi6AwLAYDVR0RBCUwI4EhYWNjb3VudHMr
|
28
28
|
cnVieWdlbXNAdGhla29tcGFuZWUuY29tMCwGA1UdEgQlMCOBIWFjY291bnRzK3J1
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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/
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
@@ -81,33 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: timecop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: '0.9'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: timecop
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.6.0
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.6.0
|
96
|
+
version: '0.9'
|
111
97
|
description: 'Ruby/ProgressBar is an extremely flexible text progress bar library
|
112
98
|
for Ruby. The output can be customized with a flexible formatting system including:
|
113
99
|
percentage, bars of various formats, elapsed time and estimated time remaining.'
|
@@ -123,15 +109,13 @@ files:
|
|
123
109
|
- lib/progressbar.rb
|
124
110
|
- lib/ruby-progressbar/base.rb
|
125
111
|
- lib/ruby-progressbar/calculators/length.rb
|
126
|
-
- lib/ruby-progressbar/calculators/
|
127
|
-
- lib/ruby-progressbar/components.rb
|
112
|
+
- lib/ruby-progressbar/calculators/smoothed_average.rb
|
128
113
|
- lib/ruby-progressbar/components/bar.rb
|
129
114
|
- lib/ruby-progressbar/components/percentage.rb
|
130
115
|
- lib/ruby-progressbar/components/rate.rb
|
131
116
|
- lib/ruby-progressbar/components/time.rb
|
132
117
|
- lib/ruby-progressbar/components/title.rb
|
133
118
|
- lib/ruby-progressbar/errors/invalid_progress_error.rb
|
134
|
-
- lib/ruby-progressbar/format.rb
|
135
119
|
- lib/ruby-progressbar/format/formatter.rb
|
136
120
|
- lib/ruby-progressbar/format/molecule.rb
|
137
121
|
- lib/ruby-progressbar/format/string.rb
|
@@ -152,7 +136,7 @@ licenses:
|
|
152
136
|
metadata:
|
153
137
|
bug_tracker_uri: https://github.com/jfelchner/ruby-progressbar/issues
|
154
138
|
changelog_uri: https://github.com/jfelchner/ruby-progressbar/blob/master/CHANGELOG.md
|
155
|
-
documentation_uri: https://github.com/jfelchner/ruby-progressbar/tree/releases/v1.
|
139
|
+
documentation_uri: https://github.com/jfelchner/ruby-progressbar/tree/releases/v1.12.0
|
156
140
|
homepage_uri: https://github.com/jfelchner/ruby-progressbar
|
157
141
|
source_code_uri: https://github.com/jfelchner/ruby-progressbar
|
158
142
|
wiki_uri: https://github.com/jfelchner/ruby-progressbar/wiki
|
@@ -171,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
155
|
- !ruby/object:Gem::Version
|
172
156
|
version: '0'
|
173
157
|
requirements: []
|
174
|
-
rubygems_version: 3.
|
158
|
+
rubygems_version: 3.1.6
|
175
159
|
signing_key:
|
176
160
|
specification_version: 4
|
177
161
|
summary: Ruby/ProgressBar is a flexible text progress bar library for Ruby.
|
metadata.gz.sig
CHANGED
Binary file
|