Class: Geoptima::Timer
- Inherits:
-
Object
- Object
- Geoptima::Timer
- Defined in:
- lib/geoptima/timer.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#full_duration ⇒ Object
readonly
Returns the value of attribute full_duration.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #describe ⇒ Object
-
#initialize(name) ⇒ Timer
constructor
A new instance of Timer.
- #reset ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Timer
Returns a new instance of Timer.
5 6 7 8 |
# File 'lib/geoptima/timer.rb', line 5 def initialize(name) @name = name reset end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
4 5 6 |
# File 'lib/geoptima/timer.rb', line 4 def duration @duration end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
4 5 6 |
# File 'lib/geoptima/timer.rb', line 4 def end_time @end_time end |
#full_duration ⇒ Object (readonly)
Returns the value of attribute full_duration.
4 5 6 |
# File 'lib/geoptima/timer.rb', line 4 def full_duration @full_duration end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/geoptima/timer.rb', line 4 def name @name end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
4 5 6 |
# File 'lib/geoptima/timer.rb', line 4 def running @running end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
4 5 6 |
# File 'lib/geoptima/timer.rb', line 4 def start_time @start_time end |
Instance Method Details
#describe ⇒ Object
33 34 35 |
# File 'lib/geoptima/timer.rb', line 33 def describe "#{name}\t#{full_duration}s" end |
#reset ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/geoptima/timer.rb', line 9 def reset @running = false @duration = 0 @full_duration = 0 @start_time = nil @end_time = nil end |
#start ⇒ Object
16 17 18 19 20 |
# File 'lib/geoptima/timer.rb', line 16 def start @duration = 0 @running = true @start_time = Time.new end |
#stop ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/geoptima/timer.rb', line 21 def stop if running @running = false @end_time = Time.new @duration = @end_time - @start_time @full_duration += @duration end @duration end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/geoptima/timer.rb', line 30 def to_s "#{name}(#{full_duration}s)" end |