progress_bar 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/progress_bar.rb +5 -3
- data/lib/progress_bar/version.rb +1 -1
- data/spec/bar_spec.rb +28 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63c44738d941428ab4348be03ab2f1744343fb7b
|
4
|
+
data.tar.gz: a78ec7e3bd7e45e56ae9fb9d07d7269d3b05dbda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 913cb8e575f72ff88aaf39d32e54e67abbe83ab6aa19540295b512641c898a038ad91b1b845604bb4fd19abc5cc4436e64a63ada61faf0dbaf27b982b83863d1
|
7
|
+
data.tar.gz: 5a483c2f3cc1e5b41949644463c8da98ecdb9509c18ab2d117971cd72fc71589b44bdba59ec08f5c59910904e211ac66f1dd8069df9d3e17aeaf8d011d4a60d8
|
data/lib/progress_bar.rb
CHANGED
@@ -98,9 +98,11 @@ class ProgressBar
|
|
98
98
|
|
99
99
|
def render_bar
|
100
100
|
return '' if bar_width < 2
|
101
|
+
progress_width = (ratio * (bar_width - 2)).floor
|
102
|
+
remainder_width = bar_width - 2 - progress_width
|
101
103
|
"[" +
|
102
|
-
"#" *
|
103
|
-
" " *
|
104
|
+
"#" * progress_width +
|
105
|
+
" " * remainder_width +
|
104
106
|
"]"
|
105
107
|
end
|
106
108
|
|
@@ -127,7 +129,7 @@ class ProgressBar
|
|
127
129
|
|
128
130
|
def terminal_width
|
129
131
|
# HighLine check takes a long time, so only update width every second.
|
130
|
-
if @terminal_width.nil? || @last_width_adjustment.nil? ||
|
132
|
+
if @terminal_width.nil? || @last_width_adjustment.nil? ||
|
131
133
|
::Time.now - @last_width_adjustment > 1
|
132
134
|
|
133
135
|
@last_width_adjustment = ::Time.now
|
data/lib/progress_bar/version.rb
CHANGED
data/spec/bar_spec.rb
CHANGED
@@ -1,43 +1,54 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe 'ProgressBar bar output' do
|
4
|
+
let(:max) { 100 }
|
5
|
+
let(:terminal_width) { 12 }
|
6
|
+
|
7
|
+
let(:progress_bar) { ProgressBar.new(max, :bar) }
|
8
|
+
|
4
9
|
before do
|
5
|
-
|
6
|
-
|
10
|
+
progress_bar.stub(:terminal_width) { terminal_width }
|
11
|
+
progress_bar.count = count
|
7
12
|
end
|
8
13
|
|
9
|
-
subject {
|
14
|
+
subject { progress_bar.to_s }
|
10
15
|
|
11
16
|
describe 'at count=0' do
|
12
|
-
|
13
|
-
@progress_bar.count = 0
|
14
|
-
end
|
17
|
+
let(:count) { 0 }
|
15
18
|
|
16
19
|
it { should == "[ ]" }
|
17
20
|
end
|
18
21
|
|
19
22
|
describe 'at count=50' do
|
20
|
-
|
21
|
-
@progress_bar.count = 50
|
22
|
-
end
|
23
|
+
let(:count) { 50 }
|
23
24
|
|
24
25
|
it { should == "[##### ]" }
|
25
26
|
end
|
26
27
|
|
27
28
|
describe 'at count=100' do
|
28
|
-
|
29
|
-
@progress_bar.count = 100
|
30
|
-
end
|
29
|
+
let(:count) { 100 }
|
31
30
|
|
32
31
|
it { should == "[##########]" }
|
33
32
|
end
|
34
33
|
|
35
|
-
describe 'at count=25 (non-integer divide, should round
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
describe 'at count=25 (non-integer divide, should round down)' do
|
35
|
+
let(:count) { 25 }
|
36
|
+
|
37
|
+
it { should == "[## ]" }
|
38
|
+
end
|
39
39
|
|
40
|
-
|
40
|
+
# https://github.com/paul/progress_bar/pull/31
|
41
|
+
describe "constant bar width" do
|
42
|
+
let(:max) { 17 }
|
43
|
+
let(:count) { 0 }
|
44
|
+
let(:terminal_width) { 80 }
|
45
|
+
|
46
|
+
it "has a constant bar width for all values of max and count" do
|
47
|
+
(count..max).each do |i|
|
48
|
+
progress_bar.count = i
|
49
|
+
expect( progress_bar.to_s.length ).to eq(80)
|
50
|
+
end
|
51
|
+
end
|
41
52
|
end
|
42
53
|
|
43
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress_bar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Sadauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: options
|