progress_bar 1.0.4 → 1.0.5

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
  SHA1:
3
- metadata.gz: 82c11d2f7b3d4a5da5b8cef320c69b753d1c7414
4
- data.tar.gz: 90ac19a0634dfabf6a8870b078540be52f865eb7
3
+ metadata.gz: 63c44738d941428ab4348be03ab2f1744343fb7b
4
+ data.tar.gz: a78ec7e3bd7e45e56ae9fb9d07d7269d3b05dbda
5
5
  SHA512:
6
- metadata.gz: 9e46bef340192719c4b09969a3e2cf9ffb973ead408a75eff11cdb9e9b05eded469760e4e9c3ad4f6abcbd2bc1981efc0a821e83ff6875e70fa9d8d544106d22
7
- data.tar.gz: 824bf7576d0c6e496f17d9a7bc055dbc4d09986a14b3d6343b3452be517e2d3c9fe4bbba835d54e67a8d078e64dd19c2447450785ddc546dae5986a14f65ddce
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
- "#" * (ratio * (bar_width - 2)).ceil +
103
- " " * ((1-ratio) * (bar_width - 2)).floor +
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
@@ -1,3 +1,3 @@
1
1
  class ProgressBar
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
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
- @progress_bar = ProgressBar.new(100, :bar)
6
- @progress_bar.stub(:terminal_width) { 12 }
10
+ progress_bar.stub(:terminal_width) { terminal_width }
11
+ progress_bar.count = count
7
12
  end
8
13
 
9
- subject { @progress_bar.to_s }
14
+ subject { progress_bar.to_s }
10
15
 
11
16
  describe 'at count=0' do
12
- before do
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
- before do
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
- before do
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 up)' do
36
- before do
37
- @progress_bar.count = 25
38
- end
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
- it { should == "[### ]" }
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
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-14 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: options