Class: ASAutotest::Stopwatch

Inherits:
Object
  • Object
show all
Defined in:
lib/asautotest/stopwatch.rb

Instance Method Summary collapse

Constructor Details

#initializeStopwatch

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_timeObject



38
39
40
# File 'lib/asautotest/stopwatch.rb', line 38

def current_time
  Time.new
end

#end_timeObject



34
35
36
# File 'lib/asautotest/stopwatch.rb', line 34

def end_time
  @end_time || current_time
end

#n_elapsed_secondsObject



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

#stopObject



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