each_with_progress 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/each_with_progress.rb +29 -0
- metadata +64 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module Enumerable
|
2
|
+
def each_with_progress(&block)
|
3
|
+
out = STDERR
|
4
|
+
count = self.count
|
5
|
+
self.each_with_index do |element,i|
|
6
|
+
out.print sprintf("%s", ewp_makeProgress(i,count)) + "\r"
|
7
|
+
block.call element
|
8
|
+
end
|
9
|
+
out.print sprintf("%s",ewp_makeProgress(count, count)) + "\r"
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
def ewp_makeProgress(iteration, total)
|
14
|
+
percent = (Float(iteration) / Float(total)) * 100
|
15
|
+
percent = (( percent / 1).round * 1).to_i
|
16
|
+
number_of_bars = percent / 5
|
17
|
+
progress = ""
|
18
|
+
for i in 0..number_of_bars do
|
19
|
+
progress = progress + "="
|
20
|
+
end
|
21
|
+
for i in 0..(19 - number_of_bars) do
|
22
|
+
progress = progress + " "
|
23
|
+
end
|
24
|
+
if percent < 10 && percent != 100
|
25
|
+
progress = progress + " "
|
26
|
+
end
|
27
|
+
return percent.to_s + "% |" + progress + "| " + iteration.to_s + "/" + total.to_s
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: each_with_progress
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Adam Gamble
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-18 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: adamgamble@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/each_with_progress.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: https://github.com/adamgamble/each_with_progress
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project: nowarning
|
59
|
+
rubygems_version: 1.3.7
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: stand in replacement for Enumerable#each that will print a progress bar to the console as it loops
|
63
|
+
test_files: []
|
64
|
+
|