timed_report 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.
- checksums.yaml +4 -4
- data/lib/timed_report.rb +26 -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: a5310dd374a0ec62462aa87099de7cdbd1806ad5
|
4
|
+
data.tar.gz: 5182b5ffb3074e0298d348fa3320f221fc8b4720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61be92be4d3c2621c594233d5dcd75bf7c84502a7c4b4c6a728462b30263d35c1c005e1eb182bc40809e7e5f73ea26fccfda35da874d1846b5063a3404551c68
|
7
|
+
data.tar.gz: e0bf3f47a8dcfe3af149c99261352fae3468f8d8ffe976942c5c9ff8b89a9d304d328cb574c89468f739bf78d3c6dd504507ac5fecc6670be0d0d0daf353ec3e
|
data/lib/timed_report.rb
CHANGED
@@ -8,8 +8,11 @@ class TimedReport
|
|
8
8
|
# Arguments:
|
9
9
|
# named: (String)
|
10
10
|
def initialize named = nil
|
11
|
+
@intermediate_output = false
|
12
|
+
|
11
13
|
@start_time = Time.now
|
12
14
|
@step_time = Time.now
|
15
|
+
|
13
16
|
@output = "\n=========================="
|
14
17
|
|
15
18
|
if named != nil
|
@@ -20,6 +23,15 @@ class TimedReport
|
|
20
23
|
@output_methods = [lambda{|m| puts(m)}]
|
21
24
|
end
|
22
25
|
|
26
|
+
# Set to _true_ if you want intermediate output to show
|
27
|
+
#
|
28
|
+
# Arguments:
|
29
|
+
# val: (Boolean)
|
30
|
+
def intermediate_output val = @intermediate_output
|
31
|
+
@intermediate_output = val
|
32
|
+
val
|
33
|
+
end
|
34
|
+
|
23
35
|
# Add a Proc or lambda that takes the report as argument.
|
24
36
|
#
|
25
37
|
# This way you can for example add Rails.logger.info or send an email besides printing to STDOUT.
|
@@ -39,6 +51,7 @@ class TimedReport
|
|
39
51
|
# >> tr.time_step()
|
40
52
|
def time_step
|
41
53
|
@step_time = Time.now
|
54
|
+
"❤"
|
42
55
|
end
|
43
56
|
|
44
57
|
# Adds a line of text including the difference in seconds between the last #add or #time_step.
|
@@ -58,6 +71,9 @@ class TimedReport
|
|
58
71
|
end
|
59
72
|
|
60
73
|
@output += "\n#{timing_info}#{txt}"
|
74
|
+
|
75
|
+
_puke("\n#{timing_info}#{txt}") if @intermediate_output
|
76
|
+
"❤"
|
61
77
|
end
|
62
78
|
|
63
79
|
# Finish the report. Call this add the end to print the report!
|
@@ -68,8 +84,17 @@ class TimedReport
|
|
68
84
|
@output += "\n--------------------------"
|
69
85
|
@output += "\nTotal time: %.5f" % (Time.now-@start_time)
|
70
86
|
@output += "\n=========================="
|
87
|
+
_puke(@output)
|
88
|
+
"❤"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Puke a string to all specified output methods.
|
92
|
+
#
|
93
|
+
# Arguments:
|
94
|
+
# txt: (String)
|
95
|
+
def _puke txt
|
71
96
|
@output_methods.each do |om|
|
72
|
-
om.call(
|
97
|
+
om.call(txt)
|
73
98
|
end
|
74
99
|
end
|
75
100
|
|