Class: Ur::Processing
Instance Attribute Summary collapse
-
#began_at_ns ⇒ Object
Returns the value of attribute began_at_ns.
Instance Method Summary collapse
Methods included from SubUr
Instance Attribute Details
#began_at_ns ⇒ Object
Returns the value of attribute began_at_ns.
14 15 16 |
# File 'lib/ur/processing.rb', line 14 def began_at_ns @began_at_ns end |
Instance Method Details
#began_at ⇒ Object
7 8 9 |
# File 'lib/ur/processing.rb', line 7 def began_at began_at_s ? Time.parse(began_at_s) : nil end |
#began_at=(time) ⇒ Object
10 11 12 |
# File 'lib/ur/processing.rb', line 10 def began_at=(time) self.began_at_s = time ? time.utc.iso8601(6) : nil end |
#begin! ⇒ Object
16 17 18 19 |
# File 'lib/ur/processing.rb', line 16 def begin! self.began_at ||= Time.now self.began_at_ns ||= Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) end |
#finish! ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ur/processing.rb', line 20 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 |