progress_bar 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +14 -0
- data/lib/progress_bar/version.rb +2 -2
- data/lib/progress_bar.rb +17 -13
- data/test/arguments_test.rb +34 -0
- metadata +38 -49
- data/lib/progress_bar/meters/bar.rb +0 -31
- data/lib/progress_bar/meters/counter.rb +0 -24
- data/lib/progress_bar/meters/elapsed.rb +0 -26
- data/lib/progress_bar/meters/eta.rb +0 -36
- data/lib/progress_bar/meters/percentage.rb +0 -20
- data/lib/progress_bar/version.rbc +0 -130
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
2
|
+
Version 2, December 2004
|
3
|
+
|
4
|
+
Copyright (C) 2011 Paul Sadauskas <psadauskas@gmail.com>
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
7
|
+
copies of this license document, and changing it is allowed as long
|
8
|
+
as the name is changed.
|
9
|
+
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
14
|
+
|
data/lib/progress_bar/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class ProgressBar
|
2
|
+
VERSION = "0.4.0"
|
3
3
|
end
|
data/lib/progress_bar.rb
CHANGED
@@ -4,26 +4,30 @@ require 'highline'
|
|
4
4
|
|
5
5
|
class ProgressBar
|
6
6
|
|
7
|
-
attr_accessor :count, :max, :
|
7
|
+
attr_accessor :count, :max, :meters
|
8
8
|
|
9
|
-
def initialize(
|
9
|
+
def initialize(*args)
|
10
10
|
|
11
|
-
@count
|
12
|
-
@max
|
13
|
-
@
|
11
|
+
@count = 0
|
12
|
+
@max = 100
|
13
|
+
@meters = [:bar, :counter, :percentage, :elapsed, :eta, :rate]
|
14
14
|
|
15
|
-
if
|
16
|
-
|
17
|
-
else
|
18
|
-
@meters = meters
|
19
|
-
end
|
15
|
+
@max = args.shift if args.first.is_a? Numeric
|
16
|
+
@meters = args unless args.empty?
|
20
17
|
|
21
|
-
@
|
18
|
+
@last_write = Time.at(0)
|
19
|
+
@start = Time.now
|
20
|
+
|
21
|
+
@hl = HighLine.new
|
22
22
|
end
|
23
23
|
|
24
24
|
def increment!(count = 1)
|
25
25
|
self.count += count
|
26
|
-
|
26
|
+
now = Time.now
|
27
|
+
if (now - @last_write) > 0.2 || self.count >= max
|
28
|
+
write
|
29
|
+
@last_write = now
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
def write
|
@@ -44,7 +48,7 @@ class ProgressBar
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def elapsed
|
47
|
-
Time.now - start
|
51
|
+
Time.now - @start
|
48
52
|
end
|
49
53
|
|
50
54
|
def rate
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe 'ProgressBar arguments' do
|
4
|
+
before do
|
5
|
+
@default_max = 100
|
6
|
+
@default_meters = [:bar, :counter, :percentage, :elapsed, :eta, :rate]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should set appropriate defaults without any arguments" do
|
10
|
+
bar = ProgressBar.new
|
11
|
+
bar.max.should == @default_max
|
12
|
+
bar.meters.should == @default_meters
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should allow a single argument specifying the max" do
|
16
|
+
bar = ProgressBar.new(123)
|
17
|
+
bar.max.should == 123
|
18
|
+
bar.meters.should == @default_meters
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should allow specifying just the meters" do
|
22
|
+
bar = ProgressBar.new(:bar, :eta)
|
23
|
+
bar.max.should == @default_max
|
24
|
+
bar.meters.should == [:bar, :eta]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow specyfing the max and meters" do
|
28
|
+
bar = ProgressBar.new(123, :bar, :eta)
|
29
|
+
bar.max.should == 123
|
30
|
+
bar.meters.should == [:bar, :eta]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
metadata
CHANGED
@@ -1,69 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress_bar
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.3.4
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Paul Sadauskas
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-07-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: options
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2156635980 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
18
|
+
requirements:
|
22
19
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
20
|
+
- !ruby/object:Gem::Version
|
24
21
|
version: 2.3.0
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: highline
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *2156635980
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: highline
|
27
|
+
requirement: &2156635480 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
29
|
+
requirements:
|
33
30
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
31
|
+
- !ruby/object:Gem::Version
|
35
32
|
version: 1.6.1
|
36
33
|
type: :runtime
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156635480
|
36
|
+
description: ! 'Give people feedback about long-running tasks without overloading
|
37
|
+
them with information: Use a progress bar, like Curl or Wget!'
|
38
|
+
email:
|
40
39
|
- psadauskas@gmail.com
|
41
40
|
executables: []
|
42
|
-
|
43
41
|
extensions: []
|
44
|
-
|
45
42
|
extra_rdoc_files: []
|
46
|
-
|
47
|
-
files:
|
43
|
+
files:
|
48
44
|
- .gitignore
|
49
45
|
- .rspec
|
50
46
|
- Gemfile
|
47
|
+
- LICENSE
|
51
48
|
- README.mkd
|
52
49
|
- Rakefile
|
53
50
|
- examples/simple.rb
|
54
51
|
- lib/progress_bar.rb
|
55
|
-
- lib/progress_bar/meters/bar.rb
|
56
|
-
- lib/progress_bar/meters/counter.rb
|
57
|
-
- lib/progress_bar/meters/elapsed.rb
|
58
|
-
- lib/progress_bar/meters/eta.rb
|
59
|
-
- lib/progress_bar/meters/percentage.rb
|
60
52
|
- lib/progress_bar/version.rb
|
61
|
-
- lib/progress_bar/version.rbc
|
62
53
|
- profile/shell_every_update
|
63
54
|
- profile/shell_every_update.gif
|
64
55
|
- profile/shell_once
|
65
56
|
- profile/shell_once.gif
|
66
57
|
- progress_bar.gemspec
|
58
|
+
- test/arguments_test.rb
|
67
59
|
- test/bar_test.rb
|
68
60
|
- test/counter_test.rb
|
69
61
|
- test/elapsed_test.rb
|
@@ -72,35 +64,32 @@ files:
|
|
72
64
|
- test/progress_bar_test.rb
|
73
65
|
- test/rate_test.rb
|
74
66
|
- test/spec_helper.rb
|
75
|
-
has_rdoc: true
|
76
67
|
homepage: http://www.github.com/paul/progress_bar
|
77
68
|
licenses: []
|
78
|
-
|
79
69
|
post_install_message:
|
80
70
|
rdoc_options: []
|
81
|
-
|
82
|
-
require_paths:
|
71
|
+
require_paths:
|
83
72
|
- lib
|
84
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
74
|
none: false
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
80
|
none: false
|
92
|
-
requirements:
|
93
|
-
- -
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version:
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
96
85
|
requirements: []
|
97
|
-
|
98
86
|
rubyforge_project: progress_bar
|
99
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.8.5
|
100
88
|
signing_key:
|
101
89
|
specification_version: 3
|
102
90
|
summary: Simple Progress Bar for output to a terminal
|
103
|
-
test_files:
|
91
|
+
test_files:
|
92
|
+
- test/arguments_test.rb
|
104
93
|
- test/bar_test.rb
|
105
94
|
- test/counter_test.rb
|
106
95
|
- test/elapsed_test.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
class ProgressBar
|
3
|
-
class Bar < Meter
|
4
|
-
|
5
|
-
attr_reader :count, :max, :width
|
6
|
-
|
7
|
-
def initialize(count, max, width)
|
8
|
-
@count, @max, @width = count, max, width
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"[" +
|
13
|
-
"#" * progress_width +
|
14
|
-
" " * remaining_width +
|
15
|
-
"]"
|
16
|
-
end
|
17
|
-
|
18
|
-
def bar_width
|
19
|
-
width - 2
|
20
|
-
end
|
21
|
-
|
22
|
-
def progress_width
|
23
|
-
((count.to_f / max) * bar_width).ceil
|
24
|
-
end
|
25
|
-
|
26
|
-
def remaining_width
|
27
|
-
bar_width - progress_width
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
|
2
|
-
class ProgressBar
|
3
|
-
class Counter < Meter
|
4
|
-
|
5
|
-
attr_reader :count, :max
|
6
|
-
|
7
|
-
def initialize(count, max)
|
8
|
-
@count, @max = count, max
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"[%#{max_counter_width}i/%i]" % [count, max]
|
13
|
-
end
|
14
|
-
|
15
|
-
def width
|
16
|
-
max.to_s.length * 2 + 3
|
17
|
-
end
|
18
|
-
|
19
|
-
def max_counter_width
|
20
|
-
max.to_s.length
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
class ProgressBar
|
2
|
-
class Elapsed < Meter
|
3
|
-
|
4
|
-
include TimeFormatter
|
5
|
-
|
6
|
-
attr_reader :start
|
7
|
-
|
8
|
-
def initialize start
|
9
|
-
@start = start
|
10
|
-
end
|
11
|
-
|
12
|
-
def elapsed
|
13
|
-
Time.now - start
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
"[#{format_interval(elapsed)}]"
|
18
|
-
end
|
19
|
-
|
20
|
-
def width
|
21
|
-
format_interval(elapsed).length + 2
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
@@ -1,36 +0,0 @@
|
|
1
|
-
class ProgressBar
|
2
|
-
class ETA < Meter
|
3
|
-
|
4
|
-
include TimeFormatter
|
5
|
-
|
6
|
-
attr_reader :start, :count, :max
|
7
|
-
|
8
|
-
def initialize start, count, max
|
9
|
-
@start, @count, @max = start, count, max
|
10
|
-
end
|
11
|
-
|
12
|
-
def elapsed
|
13
|
-
Time.now - start
|
14
|
-
end
|
15
|
-
|
16
|
-
def average
|
17
|
-
if count == 0
|
18
|
-
0
|
19
|
-
else
|
20
|
-
elapsed / count
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def remaining
|
25
|
-
(max - count) * average
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_s
|
29
|
-
"[ETA: #{format_interval(remaining)}]"
|
30
|
-
end
|
31
|
-
|
32
|
-
def width
|
33
|
-
format_interval(elapsed).length + 7
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
class ProgressBar
|
3
|
-
class Percentage < Meter
|
4
|
-
|
5
|
-
attr_reader :count, :max
|
6
|
-
|
7
|
-
def initialize count, max
|
8
|
-
@count, @max = count, max
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"[%6.2f%%]" % (count.to_f / max * 100)
|
13
|
-
end
|
14
|
-
|
15
|
-
def width
|
16
|
-
9
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
@@ -1,130 +0,0 @@
|
|
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
|