class SpeedGun::Event
Attributes
children[R]
finished_at[R]
@return [Time, nil] Finished time of event
id[R]
@return [String] Event
ID
name[R]
@return [String] Event
name
payload[R]
@return [Hash] Event
payload
started_at[R]
@return [Time] Started time of event
Public Class Methods
from_hash(hash, id = nil)
click to toggle source
# File lib/speed_gun/event.rb, line 18 def self.from_hash(hash, id = nil) new( hash['name'], hash['payload'], Time.at(hash['started_at'].to_f), hash['finished_at'] ? Time.at(hash['finished_at']) : nil ).tap do |event| event.instance_variable_set(:@id, id) if id end end
new(name, payload = {}, started_at = Time.now, finished_at = nil)
click to toggle source
# File lib/speed_gun/event.rb, line 29 def initialize(name, payload = {}, started_at = Time.now, finished_at = nil) @id = SecureRandom.uuid @name = name.to_s @payload = payload @started_at = started_at @finished_at = finished_at @children = [] end
Public Instance Methods
duration()
click to toggle source
# File lib/speed_gun/event.rb, line 50 def duration finished_at ? finished_at.to_f - started_at.to_f : 0 end
finish!()
click to toggle source
# File lib/speed_gun/event.rb, line 38 def finish! @finished_at = Time.now end
finished?()
click to toggle source
# File lib/speed_gun/event.rb, line 42 def finished? @finished_at end
roughly_finished_at()
click to toggle source
# File lib/speed_gun/event.rb, line 46 def roughly_finished_at finished_at || started_at end
to_hash()
click to toggle source
# File lib/speed_gun/event.rb, line 54 def to_hash { 'name' => name, 'payload' => payload, 'started_at' => started_at.to_f, 'finished_at' => finished? ? finished_at.to_f : nil } end