rake-echo 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/rake-echo.rb +45 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aef5c5fcf5b2668e072d13762a2dd683438043d9
|
4
|
+
data.tar.gz: 7f18f0708f398c490ebfb3ede4e3b250224086d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96367da109f4bd00460d5e4916a96cab6bdda481dff3c806ea1e9854b2f8b7fac96e9918c0ea2579681f0dbec37732e7272748a31e7dd1c5d2aa26f0aaac4625
|
7
|
+
data.tar.gz: ad9cf85448fbcab408e69b4cb5836248be96bc0d4a620993bc18f753c7dafd6910b345f3711186ac8d59a8a0748d54b38646c956007adc49c1d576949aad1089
|
data/lib/rake-echo.rb
CHANGED
@@ -1,29 +1,67 @@
|
|
1
1
|
module Echo
|
2
2
|
class ProgressBar
|
3
|
-
|
3
|
+
|
4
|
+
attr_reader :total
|
5
|
+
attr_reader :current
|
6
|
+
attr_reader :start_time
|
4
7
|
|
5
8
|
def initialize(total)
|
6
9
|
@total = total
|
7
10
|
@current = 0
|
8
|
-
@
|
11
|
+
@start_time = Time.now
|
12
|
+
@previous_time = @start_time
|
9
13
|
end
|
10
14
|
|
11
15
|
def increment(amount=1)
|
12
16
|
@current += amount
|
13
|
-
|
14
17
|
display
|
18
|
+
|
19
|
+
finish if completed?
|
15
20
|
end
|
16
21
|
|
17
22
|
def percentage
|
18
23
|
current.to_f / total.to_f
|
19
24
|
end
|
20
25
|
|
26
|
+
def completed?
|
27
|
+
@current == @total
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
21
32
|
def display
|
22
|
-
|
33
|
+
width = 20
|
34
|
+
|
35
|
+
current_col = (width * percentage).round
|
23
36
|
current_perc = (percentage * 100.0).round(2)
|
24
|
-
|
25
|
-
|
26
|
-
|
37
|
+
|
38
|
+
bar = "\r%+6.6s [%s%s] | %s" % [
|
39
|
+
current_perc.to_s + "%",
|
40
|
+
"#" * current_col,
|
41
|
+
"_" * (width - current_col),
|
42
|
+
eta
|
43
|
+
]
|
44
|
+
|
45
|
+
$stdout.print(bar)
|
46
|
+
$stdout.flush
|
47
|
+
end
|
48
|
+
|
49
|
+
def finish
|
50
|
+
$stdout.print("\n")
|
51
|
+
$stdout.flush
|
27
52
|
end
|
53
|
+
|
54
|
+
def eta
|
55
|
+
time = if @current == 0
|
56
|
+
"--:--:--"
|
57
|
+
else
|
58
|
+
elapsed = Time.now - @start_time
|
59
|
+
eta = (elapsed / @current) * (@total - @current);
|
60
|
+
Time.at(eta).utc.strftime "%H:%M:%S"
|
61
|
+
end
|
62
|
+
|
63
|
+
"ETA: %s" % time
|
64
|
+
end
|
65
|
+
|
28
66
|
end
|
29
67
|
end
|