progress-meter 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/progress-meter.rb +62 -14
- data/samples/file.rb +7 -0
- data/samples/hash-loop.rb +1 -1
- data/samples/two-loops.rb +1 -1
- metadata +41 -33
data/lib/progress-meter.rb
CHANGED
@@ -11,6 +11,11 @@
|
|
11
11
|
# already. Every now and then, it prints the progress report.
|
12
12
|
class Progress
|
13
13
|
|
14
|
+
@@progress_meters = Array.new
|
15
|
+
def self.progress_meters
|
16
|
+
@@progress_meters
|
17
|
+
end
|
18
|
+
|
14
19
|
@@monitor = false
|
15
20
|
@@desc = ""
|
16
21
|
|
@@ -50,13 +55,23 @@ class Progress
|
|
50
55
|
|
51
56
|
# Used to register a new completed loop iteration.
|
52
57
|
#
|
53
|
-
def tick
|
54
|
-
@current +=
|
58
|
+
def tick(steps = 1)
|
59
|
+
@current += steps
|
60
|
+
percent = @current.to_f/ @max.to_f
|
61
|
+
if percent - @last_report > 1.to_f/@num_reports.to_f then
|
62
|
+
report
|
63
|
+
@last_report=percent
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def set(step)
|
68
|
+
@current = step
|
55
69
|
percent = @current.to_f/ @max.to_f
|
56
70
|
if percent - @last_report > 1.to_f/@num_reports.to_f then
|
57
71
|
report
|
58
72
|
@last_report=percent
|
59
73
|
end
|
74
|
+
|
60
75
|
end
|
61
76
|
|
62
77
|
# Prints de progress report. It backs up as many lines as the meters
|
@@ -104,14 +119,14 @@ end
|
|
104
119
|
|
105
120
|
|
106
121
|
class Array
|
107
|
-
@@progress_meters = Array.new
|
108
122
|
alias :orig_each :each
|
109
123
|
|
110
124
|
def each (&block)
|
111
125
|
if Progress.active? then
|
112
|
-
|
113
|
-
|
114
|
-
|
126
|
+
progress_meters = Progress::progress_meters
|
127
|
+
progress_meters.push(Progress.new(self.length, progress_meters.size ))
|
128
|
+
orig_each {|w|block.call(w);progress_meters.last.tick;}
|
129
|
+
progress_meters.pop
|
115
130
|
else
|
116
131
|
orig_each &block
|
117
132
|
end
|
@@ -120,9 +135,10 @@ class Array
|
|
120
135
|
alias :orig_collect :collect
|
121
136
|
def collect (&block)
|
122
137
|
if Progress.active? then
|
123
|
-
|
124
|
-
|
125
|
-
|
138
|
+
progress_meters = Progress::progress_meters
|
139
|
+
progress_meters.push(Progress.new(self.length, progress_meters.size ))
|
140
|
+
res = orig_collect {|w| r = block.call(w);progress_meters.last.tick; r}
|
141
|
+
progress_meters.pop
|
126
142
|
res
|
127
143
|
else
|
128
144
|
orig_collect &block
|
@@ -136,19 +152,51 @@ end
|
|
136
152
|
|
137
153
|
|
138
154
|
class Hash
|
139
|
-
@@progress_meters = Array.new
|
140
155
|
alias :orig_each :each
|
141
156
|
def each (&block)
|
142
157
|
if Progress.active? then
|
143
|
-
|
144
|
-
|
145
|
-
orig_each {|k,v|block.call(k,v)
|
146
|
-
|
158
|
+
progress_meters = Progress::progress_meters
|
159
|
+
progress_meters.push(Progress.new(self.length, progress_meters.size ))
|
160
|
+
orig_each {|k,v|block.call(k,v);progress_meters.last.tick;}
|
161
|
+
progress_meters.pop
|
162
|
+
else
|
163
|
+
orig_each &block
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
class File
|
174
|
+
alias :orig_each :each
|
175
|
+
alias :orig_collect :collect
|
176
|
+
def each (&block)
|
177
|
+
if Progress.active? then
|
178
|
+
progress_meters = Progress::progress_meters
|
179
|
+
progress_meters.push(Progress.new(self.stat.size, progress_meters.size ))
|
180
|
+
orig_each {|l| block.call(l);progress_meters.last.set(self.pos);}
|
181
|
+
progress_meters.pop
|
147
182
|
else
|
148
183
|
orig_each &block
|
149
184
|
end
|
150
185
|
end
|
151
186
|
|
187
|
+
def collect (&block)
|
188
|
+
if Progress.active? then
|
189
|
+
progress_meters = Progress::progress_meters
|
190
|
+
progress_meters.push(Progress.new(self.stat.size, progress_meters.size ))
|
191
|
+
res = orig_collect {|l| r = block.call(l);progress_meters.last.set(self.pos); r}
|
192
|
+
progress_meters.pop
|
193
|
+
res
|
194
|
+
else
|
195
|
+
orig_collect &block
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
|
152
200
|
end
|
153
201
|
|
154
202
|
|
data/samples/file.rb
ADDED
data/samples/hash-loop.rb
CHANGED
data/samples/two-loops.rb
CHANGED
metadata
CHANGED
@@ -1,50 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: progress-meter
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2008-01-18 00:00:00 +01:00
|
8
|
-
summary: Allows to monitor the progress of some loop. Currently only Array.each, Array.collect and Hash.each
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: mikisvaz@yahoo.com
|
12
|
-
homepage:
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.0.4
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Miguel Vazquez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-02-24 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: mikisvaz@yahoo.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
31
24
|
files:
|
32
25
|
- lib/progress-meter.rb
|
33
26
|
- samples/two-loops.rb
|
34
27
|
- samples/collect.rb
|
35
28
|
- samples/hash-loop.rb
|
29
|
+
- samples/file.rb
|
36
30
|
- README
|
37
|
-
|
38
|
-
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: https://rubyforge.org/projects/progress-meter/
|
33
|
+
post_install_message:
|
39
34
|
rdoc_options: []
|
40
35
|
|
41
|
-
|
42
|
-
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
47
50
|
requirements: []
|
48
51
|
|
49
|
-
|
52
|
+
rubyforge_project: progress-meter
|
53
|
+
rubygems_version: 1.0.1
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: Allows to monitor the progress of some loop. Currently only Array.each, Array.collect and Hash.each. File.each and File.collect supported too.
|
57
|
+
test_files: []
|
50
58
|
|