Class: Raykit::Timer

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

Overview

Provides functionality to record the time execution times

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



11
12
13
# File 'lib/raykit/timer.rb', line 11

def initialize
  @start_time = Time.now
end

Instance Attribute Details

#start_timeObject

The time at which start occurred



9
10
11
# File 'lib/raykit/timer.rb', line 9

def start_time
  @start_time
end

Class Method Details

.get_elapsed_str(elapsed, pad = 0) ⇒ Object

Converts a time span in seconds to a formatted string



26
27
28
29
# File 'lib/raykit/timer.rb', line 26

def self.get_elapsed_str(elapsed, pad = 0)
  # "[" + "%.0f" % (elapsed) + "s]".ljust(pad)
  format("%.0f", elapsed) + "s".ljust(pad)
end

Instance Method Details

#elapsedObject

The elapsed time, in seconds, since the timer started



16
17
18
# File 'lib/raykit/timer.rb', line 16

def elapsed
  Time.now - @start_time
end

#elapsed_str(pad = 0) ⇒ Object

The elapsed time, in seconds, as a formatted string



21
22
23
# File 'lib/raykit/timer.rb', line 21

def elapsed_str(pad = 0)
  Timer.get_elapsed_str(elapsed, pad)
end