progress-meter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -116,6 +116,20 @@ class Array
116
116
  end
117
117
  end
118
118
 
119
+ alias :orig_collect :collect
120
+ def collect (&block)
121
+ if Progress.active? then
122
+ @@progress_meters.push(Progress.new(self.length, @@progress_meters.size ))
123
+ res = orig_collect {|w| r = block.call(w);@@progress_meters.last.tick; r}
124
+ @@progress_meters.pop
125
+ res
126
+ else
127
+ orig_collect &block
128
+ end
129
+ end
130
+
131
+
132
+
119
133
  end
120
134
 
121
135
 
@@ -135,3 +149,6 @@ class Hash
135
149
  end
136
150
 
137
151
  end
152
+
153
+
154
+
@@ -0,0 +1,11 @@
1
+ require 'lib/progress-meter'
2
+
3
+
4
+ dc = ('a'..'z').to_a
5
+ Progress.monitor
6
+ uc = dc.collect{|l|
7
+ sleep(0.2)
8
+ l.upcase
9
+ }
10
+ p uc
11
+
@@ -0,0 +1,17 @@
1
+ # This is an example using a hash. It also shows what happens when you
2
+ # print stuff. In this case, we print new lines, and the progress meter
3
+ # is always moved to the line above the last one.
4
+
5
+ require 'progress-meter'
6
+
7
+ h = Hash.new
8
+
9
+ ('a'..'z').to_a.each{|l|
10
+ h[l] = l.upcase
11
+ }
12
+
13
+ Progress.monitor
14
+ h.each{|d,u|
15
+ puts "#{d} => #{u}, "
16
+ sleep(0.2)
17
+ }
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: progress-meter
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
6
+ version: 0.0.2
7
7
  date: 2007-12-05 00:00:00 +01:00
8
8
  summary: Allows to monitor the progress of some loop. Currently only Array.each and Hash.each
9
9
  require_paths:
@@ -31,6 +31,8 @@ authors:
31
31
  files:
32
32
  - lib/progress-meter.rb
33
33
  - samples/two-loops.rb
34
+ - samples/collect.rb
35
+ - samples/hash-loop.rb
34
36
  - README
35
37
  test_files: []
36
38