Class: ASAutotest::Stopwatch
- Inherits:
-
Object
- Object
- ASAutotest::Stopwatch
- Defined in:
- lib/asautotest/stopwatch.rb
Instance Method Summary collapse
- #current_time ⇒ Object
- #end_time ⇒ Object
-
#initialize ⇒ Stopwatch
constructor
A new instance of Stopwatch.
- #n_elapsed_seconds ⇒ Object
- #round(number, n_decimals) ⇒ Object
- #stop ⇒ Object
- #to_s(decimals = 3) ⇒ Object
Constructor Details
#initialize ⇒ Stopwatch
Returns a new instance of Stopwatch.
22 23 24 |
# File 'lib/asautotest/stopwatch.rb', line 22 def initialize @start_time = current_time end |
Instance Method Details
#current_time ⇒ Object
38 39 40 |
# File 'lib/asautotest/stopwatch.rb', line 38 def current_time Time.new end |
#end_time ⇒ Object
34 35 36 |
# File 'lib/asautotest/stopwatch.rb', line 34 def end_time @end_time || current_time end |
#n_elapsed_seconds ⇒ Object
42 43 44 |
# File 'lib/asautotest/stopwatch.rb', line 42 def n_elapsed_seconds end_time - @start_time end |
#round(number, n_decimals) ⇒ Object
46 47 48 |
# File 'lib/asautotest/stopwatch.rb', line 46 def round(number, n_decimals) (number * 10 ** n_decimals).round.to_f / 10 ** n_decimals end |
#stop ⇒ Object
30 31 32 |
# File 'lib/asautotest/stopwatch.rb', line 30 def stop @end_time = current_time end |
#to_s(decimals = 3) ⇒ Object
26 27 28 |
# File 'lib/asautotest/stopwatch.rb', line 26 def to_s(decimals = 3) round(n_elapsed_seconds, decimals).to_s end |