progbar 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/progbar.rb +6 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57f66bb6df812a8370a3a2760b3e3adbaa2190a1
|
4
|
+
data.tar.gz: 3c5392504d6442558d411556539fbad1e1c54f55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9328813deca16d895cbd48f807c1efea28e97e973934c5dc6a1aab203689d4aa1401010426f983ce5e069f419c652d873672cc1abf703c9d9ee54c0145767db6
|
7
|
+
data.tar.gz: f955274acc8fefdb79e755c08b02380b4439489c056e1770f36e0dc628241a2b5b68effb1960c38fd0d08b751d43ab7057e9bdd22370ec3a4b5899b464ae3204
|
data/lib/progbar.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
class Array
|
2
2
|
def prog_each(&block)
|
3
|
+
bar_length = (`tput cols` || 80).to_i - 30
|
3
4
|
time_now = Time.now
|
4
5
|
total = self.count
|
5
6
|
last_flush = 0
|
6
7
|
flush_time = 1
|
7
8
|
self.each_with_index{|element, x|
|
8
9
|
cur = (x+1) * 100 / total
|
9
|
-
time_left = (((Time.now - time_now) * (100 - cur)) / cur).
|
10
|
+
time_left = (((Time.now - time_now) * (100 - cur)).to_f / cur).ceil
|
10
11
|
if (Time.now - last_flush).to_i >= flush_time or time_left < 1
|
11
12
|
time_left_graceful = Time.at(time_left).utc.strftime("%H:%M:%S")
|
12
13
|
if time_left > 86400
|
13
14
|
time_left_graceful = res.split(":")
|
14
|
-
time_left_graceful[0] = (time_left_graceful[0].to_i + days*24).to_s
|
15
|
+
time_left_graceful[0] = (time_left_graceful[0].to_i + days * 24).to_s
|
15
16
|
time_left_graceful = time_left_graceful.join(":")
|
16
17
|
end
|
17
18
|
print "\r"
|
18
|
-
|
19
|
+
cur_len = (bar_length * (x + 1)) / total
|
20
|
+
print "[" << (["#"] * cur_len).join << (["-"] * (bar_length - cur_len)).join << "] #{cur}% [#{time_left_graceful} left]"
|
19
21
|
last_flush = Time.now
|
20
22
|
end
|
21
|
-
block.call
|
23
|
+
block.call element if block
|
22
24
|
}
|
23
25
|
puts "\n"
|
24
26
|
"Done."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- anvyzhang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Print progress bar for array iteration
|
14
14
|
email: m@anvy.me
|