Class: RSMP::Clock
- Inherits:
-
Object
- Object
- RSMP::Clock
- Defined in:
- lib/rsmp/helpers/clock.rb
Instance Attribute Summary collapse
-
#adjustment ⇒ Object
readonly
Returns the value of attribute adjustment.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Clock
constructor
A new instance of Clock.
- #now ⇒ Object
- #reset ⇒ Object
- #set(target) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Clock
Returns a new instance of Clock.
12 13 14 |
# File 'lib/rsmp/helpers/clock.rb', line 12 def initialize @adjustment = 0 end |
Instance Attribute Details
#adjustment ⇒ Object (readonly)
Returns the value of attribute adjustment.
10 11 12 |
# File 'lib/rsmp/helpers/clock.rb', line 10 def adjustment @adjustment end |
Class Method Details
.now ⇒ Object
32 33 34 |
# File 'lib/rsmp/helpers/clock.rb', line 32 def self.now Time.now.utc end |
.parse(str) ⇒ Object
40 41 42 |
# File 'lib/rsmp/helpers/clock.rb', line 40 def self.parse(str) Time.parse(str) end |
.to_s(time = nil) ⇒ Object
36 37 38 |
# File 'lib/rsmp/helpers/clock.rb', line 36 def self.to_s(time = nil) (time || now).strftime('%FT%T.%3NZ') end |
Instance Method Details
#now ⇒ Object
24 25 26 |
# File 'lib/rsmp/helpers/clock.rb', line 24 def now Time.now.utc + @adjustment end |
#reset ⇒ Object
20 21 22 |
# File 'lib/rsmp/helpers/clock.rb', line 20 def reset @adjustment = 0 end |
#set(target) ⇒ Object
16 17 18 |
# File 'lib/rsmp/helpers/clock.rb', line 16 def set(target) @adjustment = target - Time.now end |