Class: SpeedGun::Report
- Inherits:
-
Object
- Object
- SpeedGun::Report
- Defined in:
- lib/speed_gun/report.rb
Instance Attribute Summary collapse
-
#events ⇒ Array<SpeedGun::Event>
readonly
Recorded events.
-
#id ⇒ String
readonly
Report ID.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sources ⇒ Array<SpeedGun::Source>
readonly
Profiled source codes.
Class Method Summary collapse
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize ⇒ Report
constructor
A new instance of Report.
- #latest_event_finished_at ⇒ Object
- #nearlest_event_started_at ⇒ Object
- #record(event) ⇒ Object
- #source(source) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Report
Returns a new instance of Report.
35 36 37 38 39 40 |
# File 'lib/speed_gun/report.rb', line 35 def initialize @id = SecureRandom.uuid @name = nil @sources = [] @events = [] end |
Instance Attribute Details
#events ⇒ Array<SpeedGun::Event> (readonly)
Returns Recorded events.
15 16 17 |
# File 'lib/speed_gun/report.rb', line 15 def events @events end |
#id ⇒ String (readonly)
Returns Report ID.
7 8 9 |
# File 'lib/speed_gun/report.rb', line 7 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/speed_gun/report.rb', line 9 def name @name end |
#sources ⇒ Array<SpeedGun::Source> (readonly)
Returns Profiled source codes.
12 13 14 |
# File 'lib/speed_gun/report.rb', line 12 def sources @sources end |
Class Method Details
.from_hash(hash) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |
Instance Method Details
#duration ⇒ Object
58 59 60 |
# 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 ⇒ Object
54 55 56 |
# 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 ⇒ Object
50 51 52 |
# File 'lib/speed_gun/report.rb', line 50 def nearlest_event_started_at @events.sort_by(&:started_at).first.started_at end |
#record(event) ⇒ Object
42 43 44 |
# File 'lib/speed_gun/report.rb', line 42 def record(event) @events.push(event) end |
#source(source) ⇒ Object
46 47 48 |
# File 'lib/speed_gun/report.rb', line 46 def source(source) @sources.push(source) end |
#to_hash ⇒ Object
62 63 64 65 66 67 68 |
# 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 |