lib/ur/metadata.rb in ur-0.1.0 vs lib/ur/metadata.rb in ur-0.1.1

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'ur' unless Object.const_defined?(:Ur) class Ur class Metadata include SubUr @@ -11,13 +13,16 @@ self.began_at_s = time ? time.utc.iso8601(6) : nil end attr_accessor :began_at_ns + # sets began_at from the current time def begin! self.began_at ||= Time.now self.began_at_ns ||= Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) end + + # sets the duration from the current time and began_at 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