progress_bar 0.2.0 → 0.3.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.
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format
2
+ documentation
3
+ --color
4
+ --backtrace
data/Gemfile CHANGED
@@ -4,7 +4,9 @@ source "http://rubygems.org"
4
4
  gem "highline"
5
5
  gem "options"
6
6
 
7
- group :development do
7
+ group :development, :test do
8
+ gem "rspec"
9
+ gem "timecop"
8
10
  end
9
11
 
10
12
 
File without changes
data/lib/progress_bar.rb CHANGED
@@ -6,13 +6,13 @@ class ProgressBar
6
6
 
7
7
  attr_accessor :count, :max, :start, :meters
8
8
 
9
- def initialize(max = 100, meters = :all)
9
+ def initialize(max = 100, *meters)
10
10
 
11
11
  @count = 0
12
12
  @max = max
13
13
  @start = Time.now
14
14
 
15
- if meters == :all
15
+ if meters.empty?
16
16
  @meters = [:bar, :counter, :percentage, :elapsed, :eta, :rate]
17
17
  else
18
18
  @meters = meters
@@ -56,7 +56,11 @@ class ProgressBar
56
56
  end
57
57
 
58
58
  def eta
59
- remaining / rate
59
+ if count > 0
60
+ remaining / rate
61
+ else
62
+ 0
63
+ end
60
64
  end
61
65
 
62
66
  def to_s
@@ -67,6 +71,10 @@ class ProgressBar
67
71
 
68
72
  protected
69
73
 
74
+ def print(str)
75
+ $stderr.write str
76
+ end
77
+
70
78
  def clear!
71
79
  print "\r"
72
80
  end
@@ -87,11 +95,11 @@ class ProgressBar
87
95
  end
88
96
 
89
97
  def render_counter
90
- "[%#{max.to_s.length}i/%i]" % [count, max]
98
+ "[%#{max_width}i/%i]" % [count, max]
91
99
  end
92
100
 
93
101
  def render_percentage
94
- format = (max % 10 == 0 ? "%3i" : "%6.2f")
102
+ format = (max == 100 ? "%3i" : "%6.2f")
95
103
  "[#{format}%%]" % percentage
96
104
  end
97
105
 
@@ -104,7 +112,7 @@ class ProgressBar
104
112
  end
105
113
 
106
114
  def render_rate
107
- "[%.2f/s]" % rate
115
+ "[%#{max_width+3}.2f/s]" % rate
108
116
  end
109
117
 
110
118
  def terminal_width
@@ -122,13 +130,13 @@ class ProgressBar
122
130
  end
123
131
 
124
132
  def counter_width # [ 1/100]
125
- max.to_s.length * 2 + 3
133
+ max_width * 2 + 3
126
134
  end
127
135
 
128
136
  def percentage_width
129
- if max == 100 # [ 24%]
137
+ if max == 100 # [ 24%]
130
138
  6
131
- else # [ 24.0%]
139
+ else # [ 24.0%]
132
140
  8
133
141
  end
134
142
  end
@@ -145,6 +153,10 @@ class ProgressBar
145
153
  render_rate.length
146
154
  end
147
155
 
156
+ def max_width
157
+ max.to_s.length
158
+ end
159
+
148
160
  def format_interval(interval)
149
161
  if interval > 3600
150
162
  "%02i:%02i:%02i" % [interval/3600, interval%3600/60, interval%60]
@@ -1,3 +1,3 @@
1
1
  module ProgressBar
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,130 @@
1
+ !RBIX
2
+ 4271523011621227713
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 28
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 2
40
+ 11
41
+ I
42
+ 6
43
+ I
44
+ 0
45
+ I
46
+ 0
47
+ I
48
+ 0
49
+ n
50
+ p
51
+ 5
52
+ x
53
+ 11
54
+ ProgressBar
55
+ x
56
+ 11
57
+ open_module
58
+ x
59
+ 15
60
+ __module_init__
61
+ M
62
+ 1
63
+ n
64
+ n
65
+ x
66
+ 11
67
+ ProgressBar
68
+ i
69
+ 12
70
+ 5
71
+ 66
72
+ 65
73
+ 7
74
+ 0
75
+ 7
76
+ 1
77
+ 64
78
+ 49
79
+ 2
80
+ 2
81
+ 11
82
+ I
83
+ 3
84
+ I
85
+ 0
86
+ I
87
+ 0
88
+ I
89
+ 0
90
+ n
91
+ p
92
+ 3
93
+ x
94
+ 7
95
+ VERSION
96
+ s
97
+ 5
98
+ 0.2.0
99
+ x
100
+ 9
101
+ const_set
102
+ p
103
+ 3
104
+ I
105
+ 2
106
+ I
107
+ 2
108
+ I
109
+ c
110
+ x
111
+ 67
112
+ /Users/rando/Code/personal/progress_bar/lib/progress_bar/version.rb
113
+ p
114
+ 0
115
+ x
116
+ 13
117
+ attach_method
118
+ p
119
+ 3
120
+ I
121
+ 0
122
+ I
123
+ 1
124
+ I
125
+ 1c
126
+ x
127
+ 67
128
+ /Users/rando/Code/personal/progress_bar/lib/progress_bar/version.rb
129
+ p
130
+ 0
data/test/bar_test.rb ADDED
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe 'ProgressBar bar output' do
4
+ before do
5
+ @progress_bar = ProgressBar.new(100, :bar)
6
+ @progress_bar.stub(:terminal_width) { 12 }
7
+ end
8
+
9
+ subject { @progress_bar.to_s }
10
+
11
+ describe 'at count=0' do
12
+ before do
13
+ @progress_bar.count = 0
14
+ end
15
+
16
+ it { should == "[ ]" }
17
+ end
18
+
19
+ describe 'at count=50' do
20
+ before do
21
+ @progress_bar.count = 50
22
+ end
23
+
24
+ it { should == "[##### ]" }
25
+ end
26
+
27
+ describe 'at count=100' do
28
+ before do
29
+ @progress_bar.count = 100
30
+ end
31
+
32
+ it { should == "[##########]" }
33
+ end
34
+
35
+ describe 'at count=25 (non-integer divide, should round up)' do
36
+ before do
37
+ @progress_bar.count = 25
38
+ end
39
+
40
+ it { should == "[### ]" }
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe 'ProgressBar counter output' do
4
+ before do
5
+ @progress_bar = ProgressBar.new(100, :counter)
6
+ end
7
+
8
+ subject { @progress_bar.to_s }
9
+
10
+ describe 'at count=0' do
11
+ before do
12
+ @progress_bar.count = 0
13
+ end
14
+
15
+ it { should == "[ 0/100]" }
16
+ end
17
+
18
+ describe 'at count=50' do
19
+ before do
20
+ @progress_bar.count = 50
21
+ end
22
+
23
+ it { should == "[ 50/100]" }
24
+ end
25
+
26
+ describe 'at count=100' do
27
+ before do
28
+ @progress_bar.count = 100
29
+ end
30
+
31
+ it { should == "[100/100]" }
32
+ end
33
+
34
+ describe 'with a shorter max' do
35
+ before do
36
+ @progress_bar = ProgressBar.new(42, :counter)
37
+ end
38
+
39
+ it { should == '[ 0/42]' }
40
+ end
41
+
42
+ describe 'with a longer max' do
43
+ before do
44
+ @progress_bar = ProgressBar.new(4242, :counter)
45
+ end
46
+
47
+ it { should == '[ 0/4242]' }
48
+ end
49
+
50
+ end
@@ -0,0 +1,48 @@
1
+
2
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
3
+
4
+ describe 'ProgressBar elapsed output' do
5
+ before do
6
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
7
+ @progress_bar = ProgressBar.new(100, :elapsed)
8
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
9
+ end
10
+
11
+ subject { @progress_bar.to_s }
12
+
13
+ describe 'at count=0' do
14
+ before do
15
+ @progress_bar.count = 0
16
+ end
17
+
18
+ it { should == "[00:10]" }
19
+ end
20
+
21
+ describe 'at count=50' do
22
+ before do
23
+ @progress_bar.count = 50
24
+ end
25
+
26
+ it { should == "[00:10]" }
27
+ end
28
+
29
+ describe 'at count=100' do
30
+ before do
31
+ @progress_bar.count = 100
32
+ end
33
+
34
+ it { should == "[00:10]" }
35
+ end
36
+
37
+ describe 'with times over 1 hour' do
38
+ before do
39
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
40
+ @progress_bar = ProgressBar.new(42, :elapsed)
41
+ Timecop.freeze Time.utc(2010, 3, 10, 2, 0, 0) # 2 hours later
42
+ end
43
+
44
+ it { should == '[02:00:00]' }
45
+ end
46
+
47
+ end
48
+
data/test/eta_test.rb ADDED
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe 'ProgressBar eta output' do
4
+ before do
5
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
6
+ @progress_bar = ProgressBar.new(100, :eta)
7
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
8
+ end
9
+
10
+ subject { @progress_bar.to_s }
11
+
12
+ describe 'at count=0' do
13
+ before do
14
+ @progress_bar.count = 0
15
+ end
16
+
17
+ it { should == "[00:00]" }
18
+ end
19
+
20
+ describe 'at count=50' do
21
+ before do
22
+ @progress_bar.count = 50
23
+ end
24
+
25
+ it { should == "[00:10]" }
26
+ end
27
+
28
+ describe 'at count=100' do
29
+ before do
30
+ @progress_bar.count = 100
31
+ end
32
+
33
+ it { should == "[00:00]" }
34
+ end
35
+
36
+ describe 'with times over 1 hour' do
37
+ before do
38
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
39
+ @progress_bar = ProgressBar.new(42, :eta)
40
+ @progress_bar.count = 21
41
+ Timecop.freeze Time.utc(2010, 3, 10, 2, 0, 0) # 2 hours later
42
+ end
43
+
44
+ it { should == '[02:00:00]' }
45
+ end
46
+
47
+ end
48
+
49
+
50
+
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe 'ProgressBar percentage output' do
4
+ before do
5
+ @progress_bar = ProgressBar.new(100, :percentage)
6
+ end
7
+
8
+ subject { @progress_bar.to_s }
9
+
10
+ describe 'at count=0' do
11
+ before do
12
+ @progress_bar.count = 0
13
+ end
14
+
15
+ it { should == "[ 0%]" }
16
+ end
17
+
18
+ describe 'at count=50' do
19
+ before do
20
+ @progress_bar.count = 50
21
+ end
22
+
23
+ it { should == "[ 50%]" }
24
+ end
25
+
26
+ describe 'at count=100' do
27
+ before do
28
+ @progress_bar.count = 100
29
+ end
30
+
31
+ it { should == "[100%]" }
32
+ end
33
+
34
+ describe 'with a max that is not 100' do
35
+ before do
36
+ @progress_bar = ProgressBar.new(42, :percentage)
37
+ @progress_bar.count = 21
38
+ end
39
+
40
+ it { should == '[ 50.00%]' }
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe 'ProgressBar bar output' do
4
+ before do
5
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
6
+ @progress_bar = ProgressBar.new(100)
7
+ @progress_bar.stub(:terminal_width) { 60 }
8
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
9
+ end
10
+
11
+ subject { @progress_bar.to_s }
12
+
13
+ describe 'at count=0' do
14
+ before do
15
+ @progress_bar.count = 0
16
+ end
17
+
18
+ it { should == "[ ] [ 0/100] [ 0%] [00:10] [00:00] [ 0.00/s]" }
19
+ end
20
+
21
+ describe 'at count=50' do
22
+ before do
23
+ @progress_bar.count = 50
24
+ end
25
+
26
+ it { should == "[####### ] [ 50/100] [ 50%] [00:10] [00:10] [ 5.00/s]" }
27
+ end
28
+
29
+ describe 'at count=100' do
30
+ before do
31
+ @progress_bar.count = 100
32
+ end
33
+
34
+ it { should == "[##############] [100/100] [100%] [00:10] [00:00] [ 10.00/s]" }
35
+ end
36
+
37
+ end
38
+
39
+
data/test/rate_test.rb ADDED
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe 'ProgressBar rate output' do
4
+ before do
5
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
6
+ @progress_bar = ProgressBar.new(100, :rate)
7
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
8
+ end
9
+
10
+ subject { @progress_bar.to_s }
11
+
12
+ describe 'at count=0' do
13
+ before do
14
+ @progress_bar.count = 0
15
+ end
16
+
17
+ it { should == "[ 0.00/s]" }
18
+ end
19
+
20
+ describe 'at count=50' do
21
+ before do
22
+ @progress_bar.count = 50
23
+ end
24
+
25
+ it { should == "[ 5.00/s]" }
26
+ end
27
+
28
+ describe 'at count=100' do
29
+ before do
30
+ @progress_bar.count = 100
31
+ end
32
+
33
+ it { should == "[ 10.00/s]" }
34
+ end
35
+
36
+ describe 'with a shorter max' do
37
+ before do
38
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
39
+ @progress_bar = ProgressBar.new(42, :rate)
40
+ @progress_bar.count = 21
41
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
42
+ end
43
+
44
+ it { should == '[ 2.10/s]' }
45
+ end
46
+
47
+ describe 'with a longer max' do
48
+ before do
49
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 0)
50
+ @progress_bar = ProgressBar.new(4242, :rate)
51
+ @progress_bar.count = 21
52
+ Timecop.freeze Time.utc(2010, 3, 10, 0, 0, 10) # 10 seconds later
53
+ end
54
+
55
+ it { should == '[ 2.10/s]' }
56
+ end
57
+
58
+ end
59
+
60
+
61
+
62
+
63
+
@@ -0,0 +1,12 @@
1
+
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/progress_bar'))
3
+
4
+ require 'rspec'
5
+ require 'timecop'
6
+
7
+ RSpec.configure do |cfg|
8
+ cfg.after do
9
+ Timecop.return
10
+ end
11
+ end
12
+
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progress_bar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
5
+ version: 0.3.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Paul Sasauskas
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-04-08 00:00:00 -06:00
13
+ date: 2011-04-10 00:00:00 -06:00
19
14
  default_executable:
20
15
  dependencies: []
21
16
 
@@ -30,9 +25,11 @@ extra_rdoc_files: []
30
25
 
31
26
  files:
32
27
  - .gitignore
28
+ - .rspec
33
29
  - Gemfile
34
30
  - README.mkd
35
31
  - Rakefile
32
+ - examples/simple.rb
36
33
  - lib/progress_bar.rb
37
34
  - lib/progress_bar/meters/bar.rb
38
35
  - lib/progress_bar/meters/counter.rb
@@ -40,9 +37,16 @@ files:
40
37
  - lib/progress_bar/meters/eta.rb
41
38
  - lib/progress_bar/meters/percentage.rb
42
39
  - lib/progress_bar/version.rb
40
+ - lib/progress_bar/version.rbc
43
41
  - progress_bar.gemspec
44
- - test/progres_bar_test.rb
45
- - test/test_helper.rb
42
+ - test/bar_test.rb
43
+ - test/counter_test.rb
44
+ - test/elapsed_test.rb
45
+ - test/eta_test.rb
46
+ - test/percentage_test.rb
47
+ - test/progress_bar_test.rb
48
+ - test/rate_test.rb
49
+ - test/spec_helper.rb
46
50
  has_rdoc: true
47
51
  homepage: http://www.github.com/paul/progress_bar
48
52
  licenses: []
@@ -57,26 +61,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
61
  requirements:
58
62
  - - ">="
59
63
  - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
64
  version: "0"
64
65
  required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  none: false
66
67
  requirements:
67
68
  - - ">="
68
69
  - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
70
  version: "0"
73
71
  requirements: []
74
72
 
75
73
  rubyforge_project: progress_bar
76
- rubygems_version: 1.5.2
74
+ rubygems_version: 1.6.2
77
75
  signing_key:
78
76
  specification_version: 3
79
77
  summary: Simple Progress Bar for output to a terminal
80
78
  test_files:
81
- - test/progres_bar_test.rb
82
- - test/test_helper.rb
79
+ - test/bar_test.rb
80
+ - test/counter_test.rb
81
+ - test/elapsed_test.rb
82
+ - test/eta_test.rb
83
+ - test/percentage_test.rb
84
+ - test/progress_bar_test.rb
85
+ - test/rate_test.rb
86
+ - test/spec_helper.rb
data/test/test_helper.rb DELETED
@@ -1,6 +0,0 @@
1
-
2
- require 'minitest/spec'
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/progress_bar'))
6
-