Class: Nanoc::Telemetry::Stopwatch
- Inherits:
-
Object
- Object
- Nanoc::Telemetry::Stopwatch
show all
- Defined in:
- lib/nanoc/telemetry/stopwatch.rb
Defined Under Namespace
Classes: AlreadyRunningError, NotRunningError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Stopwatch
19
20
21
22
|
# File 'lib/nanoc/telemetry/stopwatch.rb', line 19
def initialize
@duration = 0.0
@last_start = nil
end
|
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration
5
6
7
|
# File 'lib/nanoc/telemetry/stopwatch.rb', line 5
def duration
@duration
end
|
Instance Method Details
#running? ⇒ Boolean
35
36
37
|
# File 'lib/nanoc/telemetry/stopwatch.rb', line 35
def running?
!@last_start.nil?
end
|
#start ⇒ Object
24
25
26
27
|
# File 'lib/nanoc/telemetry/stopwatch.rb', line 24
def start
raise AlreadyRunningError if running?
@last_start = Time.now
end
|
#stop ⇒ Object
29
30
31
32
33
|
# File 'lib/nanoc/telemetry/stopwatch.rb', line 29
def stop
raise NotRunningError unless running?
@duration += (Time.now - @last_start)
@last_start = nil
end
|
#stopped? ⇒ Boolean
39
40
41
|
# File 'lib/nanoc/telemetry/stopwatch.rb', line 39
def stopped?
!running?
end
|