Class: RSMP::Clock

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClock

Returns a new instance of Clock.



13
14
15
# File 'lib/rsmp/rsmp.rb', line 13

def initialize
  @adjustment = 0
end

Instance Attribute Details

#adjustmentObject (readonly)

Returns the value of attribute adjustment.



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

def adjustment
  @adjustment
end

Class Method Details

.nowObject



33
34
35
# File 'lib/rsmp/rsmp.rb', line 33

def self.now
  Time.now.utc
end

.parse(str) ⇒ Object



41
42
43
# File 'lib/rsmp/rsmp.rb', line 41

def self.parse str
  Time.parse(str)
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

#nowObject



25
26
27
# File 'lib/rsmp/rsmp.rb', line 25

def now
  Time.now.utc + @adjustment
end

#resetObject



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

#to_sObject



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

def to_s
  Clock.to_s now
end