Class: Tamarillo::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/tamarillo/clock.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time) ⇒ Clock

Public: Initialize a new clock.

start_time - A Time instance when the clock was started.



16
17
18
19
# File 'lib/tamarillo/clock.rb', line 16

def initialize(start_time)
  @start_time = start_time
  @start_date = start_time.to_date
end

Instance Attribute Details

#start_dateObject (readonly)

Returns the value of attribute start_date.



11
12
13
# File 'lib/tamarillo/clock.rb', line 11

def start_date
  @start_date
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



11
12
13
# File 'lib/tamarillo/clock.rb', line 11

def start_time
  @start_time
end

Class Method Details

.nowObject

Public: Returns a clock starting at the current time.



22
23
24
# File 'lib/tamarillo/clock.rb', line 22

def self.now
  new(Time.now)
end

Instance Method Details

#elapsedObject

Public: Calculate time elapsed.

Returns the number of seconds since the clock started.



29
30
31
# File 'lib/tamarillo/clock.rb', line 29

def elapsed
  Time.now.to_i - @start_time.to_i
end