Class: RSMP::Clock

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClock

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

#adjustmentObject (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

.nowObject



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

#nowObject



24
25
26
# File 'lib/rsmp/helpers/clock.rb', line 24

def now
  Time.now.utc + @adjustment
end

#resetObject



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

#to_sObject



28
29
30
# File 'lib/rsmp/helpers/clock.rb', line 28

def to_s
  Clock.to_s now
end