Class: ShellTastic::Timer

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

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



3
4
5
# File 'lib/shelltastic/timer.rb', line 3

def initialize

end

Instance Method Details

#startTime

Creates a start time object

Parameters:

  • (nil)

Returns:

  • (Time)

    Time now object



10
11
12
# File 'lib/shelltastic/timer.rb', line 10

def start
  @start_time = Time.now
end

#stopTime

Creates a stop time object

Parameters:

  • (nil)

Returns:

  • (Time)

    Time now object



17
18
19
# File 'lib/shelltastic/timer.rb', line 17

def stop
  @stop_time = Time.now
end

#total_time(milliseconds = false) ⇒ Time

Calculates the total time elapsed

Parameters:

  • opts (Hash, nil)

    the opts passed in

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (Time)

    Time elapsed between #start and #stop

See Also:



26
27
28
29
30
31
32
# File 'lib/shelltastic/timer.rb', line 26

def total_time(milliseconds = false)
  if milliseconds
    (@stop_time - @start_time) * 1000.0
  else
    @stop_time - @start_time
  end
end