simple_progress_bar 0.1.1 → 0.1.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/simple_progress_bar.rb +14 -14
- data/simple_progress_bar.gemspec +1 -1
- 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: 2d738175b15062f8ad0c24c5ae021fd9eef7544a
|
4
|
+
data.tar.gz: d72e119a2d786cc857bad709c1a64e062a6ea93a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d24f70841ce63d5cca466b37bb7362eb78f3c9ad8deb9ac8cf2bbd845200c2537025250a6ed6c685425f02410ec080a76db66ad837044eb81a2270a0f5671106
|
7
|
+
data.tar.gz: aa0da172d63313e528637673aff95acd48e8839fad2925078eb2f4c52a5a061c7df09fd79a8acf49a917c41e81d821d0ed9f060148cf513a74730f8593a02634
|
data/lib/simple_progress_bar.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# the SimpleProgressBar class
|
2
2
|
module SimpleProgressBar
|
3
|
-
VERSION = "0.1.
|
3
|
+
VERSION = "0.1.2"
|
4
4
|
# Constructor
|
5
5
|
def initialize(max = 100.0)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
self.max ||= max #will set the default value only if it's nil
|
7
|
+
self.current ||= 0.0
|
8
|
+
self.percentage ||= 0.0
|
9
|
+
self.start_time = nil
|
10
|
+
self.previous_time = nil
|
11
11
|
end
|
12
12
|
|
13
13
|
attr_accessor :max, :current, :percentage, :start_time, :previous_time
|
@@ -18,7 +18,7 @@ module SimpleProgressBar
|
|
18
18
|
# * *Arguments* :
|
19
19
|
# - max -> value should be greater 0, will be parsed to float
|
20
20
|
def set_max(max)
|
21
|
-
|
21
|
+
self.max = (max > 0 ? max : 1)
|
22
22
|
end
|
23
23
|
|
24
24
|
# The increment function adds to the current progress value
|
@@ -27,23 +27,23 @@ module SimpleProgressBar
|
|
27
27
|
# * *Arguments* :
|
28
28
|
# - amount -> value which will be added to the current progress
|
29
29
|
def increment(amount = 1)
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
self.start_time ||= Time.now
|
31
|
+
self.current = (self.current + amount < self.max ? self.current + amount : self.max)
|
32
|
+
self.previous_time ||= Time.now
|
33
33
|
calc_percent
|
34
34
|
end
|
35
35
|
|
36
36
|
# The time_to_finish method calculates the secondes needed to finish
|
37
37
|
# based on the average time between increments
|
38
38
|
def time_to_finish
|
39
|
-
past_time = Time.now -
|
40
|
-
seconds_to_go = past_time *
|
39
|
+
past_time = Time.now - self.start_time
|
40
|
+
seconds_to_go = past_time * self.max / self.current - past_time
|
41
41
|
puts "time to go: #{seconds_to_go.round}s"
|
42
42
|
end
|
43
43
|
|
44
44
|
# Inspect function to show the object and the current/max for easy debugging
|
45
45
|
def inspect
|
46
|
-
"#<SimpleProgressBar:#{
|
46
|
+
"#<SimpleProgressBar:#{self.current}/#{self.max}>"
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
@@ -51,6 +51,6 @@ module SimpleProgressBar
|
|
51
51
|
# The percent function calculates the percentage
|
52
52
|
# This method is called before every update, so it will be up to date
|
53
53
|
def calc_percent
|
54
|
-
|
54
|
+
self.percentage = (self.current <= self.max ? self.current/self.max*100 : self.max)
|
55
55
|
end
|
56
56
|
end
|
data/simple_progress_bar.gemspec
CHANGED