Class: Camayoc::Timer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stats, name) ⇒ Timer

Returns a new instance of Timer.



6
7
8
9
# File 'lib/camayoc/timer.rb', line 6

def initialize(stats,name)
  self.stats = stats
  self.name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/camayoc/timer.rb', line 4

def name
  @name
end

#start_timeObject

Returns the value of attribute start_time.



4
5
6
# File 'lib/camayoc/timer.rb', line 4

def start_time
  @start_time
end

#statsObject

Returns the value of attribute stats.



4
5
6
# File 'lib/camayoc/timer.rb', line 4

def stats
  @stats
end

#stop_timeObject

Returns the value of attribute stop_time.



4
5
6
# File 'lib/camayoc/timer.rb', line 4

def stop_time
  @stop_time
end

Instance Method Details

#durationObject



20
21
22
# File 'lib/camayoc/timer.rb', line 20

def duration
  (duration_seconds*1000).round
end

#duration_secondsObject



24
25
26
# File 'lib/camayoc/timer.rb', line 24

def duration_seconds
  stop_time - start_time
end

#realtimeObject



32
33
34
35
36
37
38
# File 'lib/camayoc/timer.rb', line 32

def realtime
  start
  yield
  stop
  save
  duration_seconds
end

#save(options = {}) ⇒ Object



28
29
30
# File 'lib/camayoc/timer.rb', line 28

def save(options={})
  stats.timing(name,duration,options)
end

#startObject



11
12
13
# File 'lib/camayoc/timer.rb', line 11

def start
  self.start_time = Time.now.to_f
end

#stopObject



15
16
17
18
# File 'lib/camayoc/timer.rb', line 15

def stop
  self.stop_time = Time.now.to_f
  duration
end