counted_each 0.0.3 → 0.0.4
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/VERSION +1 -1
- data/counted_each.gemspec +2 -2
- data/lib/counted_each.rb +7 -3
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/counted_each.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{counted_each}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["bauersman"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-08}
|
13
13
|
s.description = %q{Array#each with status output}
|
14
14
|
s.email = %q{bauerei@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/counted_each.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module CountedEach
|
2
2
|
def counted_each(*args, &block)
|
3
|
-
::CountedEach::Counter.new(self).iterate(&block)
|
3
|
+
::CountedEach::Counter.new(self).iterate(false, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def counted_each_with_index(*args, &block)
|
7
|
+
::CountedEach::Counter.new(self).iterate(true, &block)
|
4
8
|
end
|
5
9
|
|
6
10
|
class Counter
|
@@ -9,12 +13,12 @@ module CountedEach
|
|
9
13
|
@t_start = nil
|
10
14
|
end
|
11
15
|
|
12
|
-
def iterate(&block)
|
16
|
+
def iterate(with_index, &block)
|
13
17
|
@total = @list.count
|
14
18
|
start
|
15
19
|
@list.each_with_index do |item, pos|
|
16
20
|
@current = pos
|
17
|
-
block.call(item)
|
21
|
+
with_index ? block.call(item, pos) : block.call(item)
|
18
22
|
Config.output.print " %i/%i Elapsed: %s Time to Complete: %s \r" % [pos+1, @total, time_format(elapsed), time_format(to_go)]
|
19
23
|
Config.output.flush
|
20
24
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- bauersman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-08 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|