Class: RSMP::Clock
- Inherits:
-
Object
- Object
- RSMP::Clock
- Defined in:
- lib/rsmp/rsmp.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.
13 14 15 |
# File 'lib/rsmp/rsmp.rb', line 13 def initialize @adjustment = 0 end |
Instance Attribute Details
#adjustment ⇒ Object (readonly)
Returns the value of attribute adjustment.
11 12 13 |
# File 'lib/rsmp/rsmp.rb', line 11 def adjustment @adjustment end |
Class Method Details
.now ⇒ Object
33 34 35 |
# File 'lib/rsmp/rsmp.rb', line 33 def self.now Time.now.utc end |
.to_s(time = nil) ⇒ Object
37 38 39 |
# File 'lib/rsmp/rsmp.rb', line 37 def self.to_s time=nil (time || now).strftime("%FT%T.%3NZ") end |
Instance Method Details
#now ⇒ Object
25 26 27 |
# File 'lib/rsmp/rsmp.rb', line 25 def now Time.now.utc + @adjustment end |
#reset ⇒ Object
21 22 23 |
# File 'lib/rsmp/rsmp.rb', line 21 def reset @adjustment = 0 end |
#set(target) ⇒ Object
17 18 19 |
# File 'lib/rsmp/rsmp.rb', line 17 def set target @adjustment = target - Time.now end |