interval_timer 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d88dbd392209a5d3a494277feefb8ca47b5cf140
4
- data.tar.gz: ac43d289695a9a9102549376e7dc51b3ffdab16e
2
+ SHA256:
3
+ metadata.gz: d88e444bf3d59705215ce4f0d444ff3e28e9da9bbc01ee4086ddc9fe583e27fa
4
+ data.tar.gz: 6f58326317d12b3419beec95785fe1b687ad4e31f444c15d64209c41553ce3fa
5
5
  SHA512:
6
- metadata.gz: 61098145ee1587303eed5b234586735517b305989c797aac81fac5a892cfa5bda152702475159119117fcb562d073f86842a0cee7eb607030fcd6ca437e2470e
7
- data.tar.gz: 3a47159c815c6ff21eaad8a8abdc24f8e435f9f98c77e3bd4d25d76869c4eae254286b0a808d5c405da74374d58aabe2c2a4e6c798f608a7e98a49348c953bee
6
+ metadata.gz: 3d08c5cc2a471d4822b06a33c0c9af69d22ddcda253792d24171914f24258fbceb2c8f232d11d33fd6d5d33ab679755c61ae0d826e191ca7cfb93aadf362c4d9
7
+ data.tar.gz: 2f9e760fe17b41a7fd4d64cbee59fdf0c1dea0788f559fe7186bebfdb606f404e7311c3791b66d1703e0918e45b673ac965297c8f2012a3d08ff1b0f7f171f8f
@@ -0,0 +1,72 @@
1
+ class IntervalTimer
2
+ def self.started
3
+ timer = new
4
+ timer.start
5
+ timer
6
+ end
7
+
8
+ def start
9
+ raise "Already started" if @start_time
10
+
11
+ @start_time = Time.now
12
+ end
13
+
14
+ def check_in(message = nil)
15
+ check_in = build_check_in(message)
16
+ check_ins.push(check_in)
17
+ check_in
18
+ end
19
+ alias_method :mark, :check_in
20
+
21
+ def report(message = nil)
22
+ [
23
+ report_header(message).join("\n"),
24
+ report_body.join("\n")
25
+ ].join("\n")
26
+ end
27
+
28
+ def check_ins
29
+ @check_ins ||= []
30
+ end
31
+
32
+ private
33
+
34
+ def build_check_in(message)
35
+ { created_at: Time.now, message: message }
36
+ end
37
+
38
+ def report_header(message)
39
+ output = []
40
+
41
+ output << ""
42
+
43
+ output <<
44
+ "IntervalTimer report" + ( message.nil? ? '' : ": #{ message }" )
45
+
46
+ output << "start_time: #{@start_time}"
47
+
48
+ output
49
+ end
50
+
51
+ def report_body
52
+ output = []
53
+
54
+ check_ins.each_with_index do |x, i|
55
+ last = i == 0 ? nil : check_ins[i - 1]
56
+
57
+ output.push report_line(x, last)
58
+ end
59
+
60
+ output
61
+ end
62
+
63
+ def report_line(x, last)
64
+ if last
65
+ since_last = x[:created_at] - last[:created_at]
66
+ else
67
+ since_last = x[:created_at] - @start_time
68
+ end
69
+
70
+ "#{x[:created_at]} -- #{ since_last.round(3) } -- #{x[:message]}"
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ class IntervalTimer
2
+ VERSION = '0.0.3'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interval_timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Griffiths
@@ -47,6 +47,8 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - lib/interval_timer.rb
50
+ - lib/interval_timer/interval_timer.rb
51
+ - lib/interval_timer/version.rb
50
52
  homepage: https://rubygems.org/gems/interval_timer
51
53
  licenses:
52
54
  - MIT
@@ -66,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
68
  - !ruby/object:Gem::Version
67
69
  version: '0'
68
70
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.4.5
71
+ rubygems_version: 3.1.4
71
72
  signing_key:
72
73
  specification_version: 4
73
74
  summary: Code profiling tool that lets you track how long things take.