timed_report 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/timed_report.rb +26 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c67f6577b5f9d51fda52184da04ee587e70f83be
4
- data.tar.gz: 706568a4282371dea4a199c7244c558f0795b9c8
3
+ metadata.gz: a5310dd374a0ec62462aa87099de7cdbd1806ad5
4
+ data.tar.gz: 5182b5ffb3074e0298d348fa3320f221fc8b4720
5
5
  SHA512:
6
- metadata.gz: 9a478a91b3df59866b04df1b424808c54a17d7c6fe50588d9a3d7de9aed8f4e8cdb68cfa6f1206931df1c72c14f4df9aec639d75321eba2ee5d20d11147f1a34
7
- data.tar.gz: cc947e7489d580b807a4b6ffc3b045ce06e329bde296e4c1ed2c07a881ce6b348aedcff989e678dfa3abd122bd1df1856f4455dcd1c17a7b3c998d170e0fdd46
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(@output)
97
+ om.call(txt)
73
98
  end
74
99
  end
75
100
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timed_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Aizenberg