task_progress_bar 1.0.0 → 1.0.1
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
- data/README.md +23 -1
- data/Rakefile +10 -0
- data/lib/task_progress_bar.rb +69 -0
- data/lib/task_progress_bar/version.rb +3 -0
- data/task_progress_bar.gemspec +18 -0
- data/test/test_helper.rb +2 -0
- data/test/test_task_progress_bar.rb +154 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4951398aea0825dace0480f6e313f6365c39d978
|
4
|
+
data.tar.gz: 0351e5f1ca45b52f21ddf1efd1092feaa57aeb17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbb158cd59484f899dce00491e57ec29adbb0d7b9e64786c775953a43c105bd64a606fa1737f9dbdfacb634d305cdda2da5ac34b01db7799ab9e10f2be8f1599
|
7
|
+
data.tar.gz: e04dbcec0e6f8476107fcae0194ffc20cd5d22828a0d2615eec3a2c3270ccf1c5a28f28f8e79235203cdf468204a9254e73193be2e56887e3ce08348fb7afa13
|
data/README.md
CHANGED
@@ -1 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# TaskProgressBar
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/task_progress_bar)
|
4
|
+
[](https://travis-ci.org/douglasresende/task_progress_bar)
|
5
|
+
|
6
|
+
## Getting started
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
bar = TaskProgressBar.new( 100 )
|
10
|
+
1..10.times{ bar.step() }
|
11
|
+
# output
|
12
|
+
[10/100][##### ][10%][00:00:01][00:00:15]
|
13
|
+
```
|
14
|
+
|
15
|
+
### Contributors
|
16
|
+
|
17
|
+
https://github.com/douglasresende/task_progress_bar/graphs/contributors
|
18
|
+
|
19
|
+
## License
|
20
|
+
|
21
|
+
MIT License. Copyright 2017 Douglas Resende. http://github.com/douglasresende/task_progress_bar
|
22
|
+
|
23
|
+
You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'task_progress_bar/version'
|
2
|
+
|
3
|
+
class TaskProgressBar
|
4
|
+
def initialize(total)
|
5
|
+
@total = total || 1
|
6
|
+
@total_bar = ( total < 50 ? total : 50 )
|
7
|
+
@start_time = Time.now
|
8
|
+
@i = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def step
|
12
|
+
self.count
|
13
|
+
STDOUT.print self.bar
|
14
|
+
end
|
15
|
+
|
16
|
+
def bar
|
17
|
+
"\r[%d/%d][%s][%d%%][%s][%s]" % [@i, @total, green_elapsed_bar, elapsed_percent, elapsed_time_formated, time_left]
|
18
|
+
end
|
19
|
+
|
20
|
+
def count(value = 1)
|
21
|
+
@i += value
|
22
|
+
end
|
23
|
+
|
24
|
+
def symbol
|
25
|
+
'#'
|
26
|
+
end
|
27
|
+
|
28
|
+
def total_progress
|
29
|
+
@total / @total_bar
|
30
|
+
end
|
31
|
+
|
32
|
+
def bar_quantity
|
33
|
+
((@i*1.00/total_progress).to_i)
|
34
|
+
end
|
35
|
+
|
36
|
+
def green_elapsed_bar
|
37
|
+
"\033[32m#{ elapsed_bar }\033[0m"
|
38
|
+
end
|
39
|
+
|
40
|
+
def elapsed_bar
|
41
|
+
"%-#{@total_bar}s" % [symbol * bar_quantity]
|
42
|
+
end
|
43
|
+
|
44
|
+
def elapsed_percent
|
45
|
+
((@i*1.00/@total)*100).to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
def elapsed_time
|
49
|
+
Time.now - @start_time
|
50
|
+
end
|
51
|
+
|
52
|
+
def elapsed_time_formated
|
53
|
+
time_formated( elapsed_time )
|
54
|
+
end
|
55
|
+
|
56
|
+
def time_left_in_seconds
|
57
|
+
return 0 if @i == 0
|
58
|
+
( (elapsed_time / @i) * (@total.to_f - @i) ).to_i
|
59
|
+
end
|
60
|
+
|
61
|
+
def time_left
|
62
|
+
time_formated( time_left_in_seconds )
|
63
|
+
end
|
64
|
+
|
65
|
+
def time_formated( value )
|
66
|
+
Time.at( value ).utc.strftime("%H:%M:%S")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'task_progress_bar/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'task_progress_bar'
|
6
|
+
s.version = TaskProgressBar::VERSION
|
7
|
+
s.authors = ['Douglas R Camargo']
|
8
|
+
s.email = ['douglas@maxstudio.com.br']
|
9
|
+
s.homepage = 'https://github.com/douglasresende/task_progress_bar'
|
10
|
+
s.description = %q{A simple Ruby gem to show in terminal a progress bar as a task monitor, step by step.}
|
11
|
+
s.summary = %q{A simple Ruby gem to show in terminal a progress bar as a task monitor, step by step.}
|
12
|
+
s.date = %q{2017-03-01}
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
describe TaskProgressBar do
|
4
|
+
parallelize_me!
|
5
|
+
|
6
|
+
let(:total) { 100 }
|
7
|
+
let(:task_progress_bar){ TaskProgressBar.new( total ) }
|
8
|
+
|
9
|
+
describe '#step' do
|
10
|
+
subject { task_progress_bar.step() }
|
11
|
+
|
12
|
+
it 'returns the output bar string' do
|
13
|
+
expected_result = ''
|
14
|
+
STDOUT.stub :print, expected_result do
|
15
|
+
assert_equal expected_result, subject
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#bar' do
|
21
|
+
subject { task_progress_bar.bar() }
|
22
|
+
|
23
|
+
it 'should return a Bar as a string' do
|
24
|
+
expected_result = "\r[0/100][## ][0%][00:00:00][00:00:01]"
|
25
|
+
|
26
|
+
task_progress_bar.stub(:green_elapsed_bar, '## ') do
|
27
|
+
task_progress_bar.stub(:elapsed_percent, 0) do
|
28
|
+
task_progress_bar.stub(:elapsed_time_formated, '00:00:00') do
|
29
|
+
task_progress_bar.stub(:time_left, '00:00:01') do
|
30
|
+
assert_equal expected_result, subject
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#count' do
|
39
|
+
describe 'value default' do
|
40
|
+
subject { task_progress_bar.count() }
|
41
|
+
|
42
|
+
it 'should sum @i with 1' do
|
43
|
+
assert_equal 1, subject
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'many count method called' do
|
47
|
+
it 'it should sum @i many count method called' do
|
48
|
+
task_progress_bar.count()
|
49
|
+
task_progress_bar.count()
|
50
|
+
task_progress_bar.count()
|
51
|
+
task_progress_bar.count()
|
52
|
+
assert_equal 5, subject
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'value by param' do
|
58
|
+
subject { task_progress_bar.count( 3 ) }
|
59
|
+
|
60
|
+
it 'should sum @i with value' do
|
61
|
+
assert_equal 3, subject
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#symbol' do
|
67
|
+
subject { task_progress_bar.symbol }
|
68
|
+
|
69
|
+
it 'should return the default symbol' do
|
70
|
+
assert_equal '#', subject
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#green_elapsed_bar' do
|
75
|
+
subject { task_progress_bar.green_elapsed_bar() }
|
76
|
+
|
77
|
+
it 'return the elapsed_bar with green terminal output string' do
|
78
|
+
expected_result = 10
|
79
|
+
task_progress_bar.stub(:elapsed_bar, expected_result) do
|
80
|
+
assert_equal "\033[32m#{ expected_result }\033[0m", subject
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#elapsed_bar' do
|
86
|
+
it 'returns the string with percentage and symbols bar quantity' do
|
87
|
+
task_progress_bar.count()
|
88
|
+
task_progress_bar.stub :bar_quantity, 10 do
|
89
|
+
assert_equal task_progress_bar.elapsed_bar, "########## "
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#elapsed_percent' do
|
95
|
+
it 'returns the integer percentage' do
|
96
|
+
0..(total/2).times { task_progress_bar.count() }
|
97
|
+
assert_equal 50, task_progress_bar.elapsed_percent
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#elapsed_time' do
|
102
|
+
it 'should return the Time now less @start_time' do
|
103
|
+
task_progress_bar.count()
|
104
|
+
Time.stub :now, Time.at( Time.now.to_i + 11 ) do
|
105
|
+
assert_equal 10, task_progress_bar.elapsed_time.to_i
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#elapsed_time_formated' do
|
111
|
+
it 'should return the Time now less @start_time formated with %H:%M:%S' do
|
112
|
+
task_progress_bar.count()
|
113
|
+
Time.stub :now, Time.at( Time.now.to_i + 11 ) do
|
114
|
+
assert_equal '00:00:10', task_progress_bar.elapsed_time_formated
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#time_left_in_seconds' do
|
120
|
+
subject { task_progress_bar.time_left_in_seconds }
|
121
|
+
|
122
|
+
describe '@i is zero' do
|
123
|
+
it 'should return 0' do
|
124
|
+
assert_equal 0, subject
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '@i isnt zero' do
|
129
|
+
it 'should return the time elapsed in seconds' do
|
130
|
+
0..50.times { task_progress_bar.count() }
|
131
|
+
|
132
|
+
Time.stub :now, Time.at( Time.now.to_i + 11 ) do
|
133
|
+
assert_equal 10, subject
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#time_left' do
|
140
|
+
it 'should return the Time at time_left_in_seconds formated with %H:%M:%S' do
|
141
|
+
task_progress_bar.stub :time_left_in_seconds, 3930 do
|
142
|
+
assert_equal '01:05:30', task_progress_bar.time_left
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#time_formated' do
|
148
|
+
it 'should return the Time formated with %H:%M:%S' do
|
149
|
+
value = Time.at( 3930 )
|
150
|
+
assert_equal '01:05:30', task_progress_bar.time_formated( value )
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: task_progress_bar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas R Camargo
|
@@ -20,6 +20,12 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- ".gitignore"
|
22
22
|
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/task_progress_bar.rb
|
25
|
+
- lib/task_progress_bar/version.rb
|
26
|
+
- task_progress_bar.gemspec
|
27
|
+
- test/test_helper.rb
|
28
|
+
- test/test_task_progress_bar.rb
|
23
29
|
homepage: https://github.com/douglasresende/task_progress_bar
|
24
30
|
licenses:
|
25
31
|
- MIT
|
@@ -45,4 +51,6 @@ signing_key:
|
|
45
51
|
specification_version: 4
|
46
52
|
summary: A simple Ruby gem to show in terminal a progress bar as a task monitor, step
|
47
53
|
by step.
|
48
|
-
test_files:
|
54
|
+
test_files:
|
55
|
+
- test/test_helper.rb
|
56
|
+
- test/test_task_progress_bar.rb
|