Module: Ur::Metadata

Includes:
SubUr
Defined in:
lib/ur/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SubUr

#ur

Instance Attribute Details

#began_at_nsObject

Returns the value of attribute began_at_ns.



16
17
18
# File 'lib/ur/metadata.rb', line 16

def began_at_ns
  @began_at_ns
end

Instance Method Details

#began_atObject



9
10
11
# File 'lib/ur/metadata.rb', line 9

def began_at
  began_at_s ? Time.parse(began_at_s) : nil
end

#began_at=(time) ⇒ Object



12
13
14
# File 'lib/ur/metadata.rb', line 12

def began_at=(time)
  self.began_at_s = time ? time.utc.iso8601(6) : nil
end

#begin!Object

sets began_at from the current time



19
20
21
22
# File 'lib/ur/metadata.rb', line 19

def begin!
  self.began_at = Time.now
  self.began_at_ns = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
end

#finish!Object

sets the duration from the current time and began_at



25
26
27
28
29
30
31
32
33
34
# File 'lib/ur/metadata.rb', line 25

def finish!
  return if duration
  if began_at_ns
    now_ns = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
    self.duration = (now_ns - began_at_ns) * 1e-9
  elsif began_at
    now = Time.now
    self.duration = (now.to_f - began_at.to_f)
  end
end