Class: Vizsla::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/vizsla/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



7
8
9
10
# File 'lib/vizsla/timer.rb', line 7

def initialize
  @start_time = nil
  @stop_time = nil
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'lib/vizsla/timer.rb', line 5

def events
  @events
end

Instance Method Details

#collect_eventsObject



23
24
25
# File 'lib/vizsla/timer.rb', line 23

def collect_events
  @events = Recorder.events
end

#elapsedObject



27
28
29
# File 'lib/vizsla/timer.rb', line 27

def elapsed
  "#{(@stop_time - @start_time).round 2}s"
end

#start!Object



12
13
14
15
# File 'lib/vizsla/timer.rb', line 12

def start!
  @start_time = Time.now
  Recorder.start_recording
end

#stop!Object



17
18
19
20
21
# File 'lib/vizsla/timer.rb', line 17

def stop!
  collect_events
  Recorder.stop_recording
  @stop_time = Time.now
end