Class: Profiler::Models::TimelineEvent
- Inherits:
-
Object
- Object
- Profiler::Models::TimelineEvent
- Defined in:
- lib/profiler/models/timeline_event.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
- #add_child(event) ⇒ Object
-
#initialize(name:, started_at:, finished_at:, payload: {}, category: nil) ⇒ TimelineEvent
constructor
A new instance of TimelineEvent.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(name:, started_at:, finished_at:, payload: {}, category: nil) ⇒ TimelineEvent
Returns a new instance of TimelineEvent.
8 9 10 11 12 13 14 15 16 |
# File 'lib/profiler/models/timeline_event.rb', line 8 def initialize(name:, started_at:, finished_at:, payload: {}, category: nil) @name = name @started_at = started_at @finished_at = finished_at @duration = ((finished_at - started_at) * 1000).round(2) # milliseconds @payload = payload @category = category @children = [] end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
6 7 8 |
# File 'lib/profiler/models/timeline_event.rb', line 6 def category @category end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/profiler/models/timeline_event.rb', line 6 def children @children end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/profiler/models/timeline_event.rb', line 6 def duration @duration end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
6 7 8 |
# File 'lib/profiler/models/timeline_event.rb', line 6 def finished_at @finished_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/profiler/models/timeline_event.rb', line 6 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
6 7 8 |
# File 'lib/profiler/models/timeline_event.rb', line 6 def payload @payload end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
6 7 8 |
# File 'lib/profiler/models/timeline_event.rb', line 6 def started_at @started_at end |
Instance Method Details
#add_child(event) ⇒ Object
18 19 20 |
# File 'lib/profiler/models/timeline_event.rb', line 18 def add_child(event) @children << event end |
#to_h ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/profiler/models/timeline_event.rb', line 22 def to_h h = { name: @name, started_at: @started_at, finished_at: @finished_at, duration: @duration, payload: @payload, children: @children.map(&:to_h) } h[:category] = @category if @category h end |
#to_json(*args) ⇒ Object
35 36 37 |
# File 'lib/profiler/models/timeline_event.rb', line 35 def to_json(*args) to_h.to_json(*args) end |