Class: Camayoc::Timer
- Inherits:
-
Object
- Object
- Camayoc::Timer
- Defined in:
- lib/camayoc/timer.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#stop_time ⇒ Object
Returns the value of attribute stop_time.
Instance Method Summary collapse
- #duration ⇒ Object
- #duration_seconds ⇒ Object
-
#initialize(stats, name) ⇒ Timer
constructor
A new instance of Timer.
- #realtime ⇒ Object
- #save(options = {}) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/camayoc/timer.rb', line 4 def name @name end |
#start_time ⇒ Object
Returns the value of attribute start_time.
4 5 6 |
# File 'lib/camayoc/timer.rb', line 4 def start_time @start_time end |
#stats ⇒ Object
Returns the value of attribute stats.
4 5 6 |
# File 'lib/camayoc/timer.rb', line 4 def stats @stats end |
#stop_time ⇒ Object
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
#duration ⇒ Object
20 21 22 |
# File 'lib/camayoc/timer.rb', line 20 def duration (duration_seconds*1000).round end |
#duration_seconds ⇒ Object
24 25 26 |
# File 'lib/camayoc/timer.rb', line 24 def duration_seconds stop_time - start_time end |
#realtime ⇒ Object
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(={}) stats.timing(name,duration,) end |
#start ⇒ Object
11 12 13 |
# File 'lib/camayoc/timer.rb', line 11 def start self.start_time = Time.now.to_f end |
#stop ⇒ Object
15 16 17 18 |
# File 'lib/camayoc/timer.rb', line 15 def stop self.stop_time = Time.now.to_f duration end |