class SpeedGun::Report
Attributes
events[R]
@return [Array<SpeedGun::Event>] Recorded events
id[R]
@return [String] Report
ID
name[RW]
sources[R]
@return [Array<SpeedGun::Source>] Profiled source codes
Public Class Methods
from_hash(hash)
click to toggle source
# File lib/speed_gun/report.rb, line 17 def self.from_hash(hash) report = new hash['sources'].map! do |source_id, hash| SpeedGun::Source.from_hash(hash, source_id) end hash['events'].map! do |event_id, hash| SpeedGun::Event.from_hash(hash, event_id) end hash.each_pair do |key, val| report.instance_variable_set(:"@#{key}", val) end report end
new()
click to toggle source
# File lib/speed_gun/report.rb, line 35 def initialize @id = SecureRandom.uuid @name = nil @sources = [] @events = [] end
Public Instance Methods
duration()
click to toggle source
# File lib/speed_gun/report.rb, line 58 def duration latest_event_finished_at.to_f - nearlest_event_started_at.to_f end
latest_event_finished_at()
click to toggle source
# File lib/speed_gun/report.rb, line 54 def latest_event_finished_at @events.sort_by { |event| event.roughly_finished_at.to_f * -1 }.first.roughly_finished_at end
nearlest_event_started_at()
click to toggle source
# File lib/speed_gun/report.rb, line 50 def nearlest_event_started_at @events.sort_by(&:started_at).first.started_at end
record(event)
click to toggle source
# File lib/speed_gun/report.rb, line 42 def record(event) @events.push(event) end
source(source)
click to toggle source
# File lib/speed_gun/report.rb, line 46 def source(source) @sources.push(source) end
to_hash()
click to toggle source
# File lib/speed_gun/report.rb, line 62 def to_hash { name: name, sources: sources.map { |source| [ source.id, source.to_hash ] }, events: events.map { |event| [event.id, event.to_hash] } } end