Class: Tamarillo::Clock
- Inherits:
-
Object
- Object
- Tamarillo::Clock
- Defined in:
- lib/tamarillo/clock.rb
Instance Attribute Summary collapse
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Class Method Summary collapse
-
.now ⇒ Object
Public: Returns a clock starting at the current time.
Instance Method Summary collapse
-
#elapsed ⇒ Object
Public: Calculate time elapsed.
-
#initialize(start_time) ⇒ Clock
constructor
Public: Initialize a new clock.
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_date ⇒ Object (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_time ⇒ Object (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
.now ⇒ Object
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
#elapsed ⇒ Object
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 |