Class: TraceViz::TraceData::Node

Inherits:
Base
  • Object
show all
Defined in:
lib/trace_viz/trace_data/node.rb

Direct Known Subclasses

RootNode, SummaryNode, TracePoint::Base

Instance Attribute Summary collapse

Attributes included from TraceViz::Traits::TimeTrackable

#timestamp

Attributes included from TraceViz::Traits::DepthTrackable

#depth

Instance Method Summary collapse

Methods inherited from Base

#action, #event, #key, #klass, #line_number, #path

Methods included from TraceViz::Traits::TimeTrackable

#record_timestamp

Methods included from TraceViz::Traits::DepthTrackable

#assign_depth

Methods included from Helpers::ConfigHelper

#config, #fetch_general_config

Constructor Details

#initializeNode

Returns a new instance of Node.



11
12
13
14
15
16
# File 'lib/trace_viz/trace_data/node.rb', line 11

def initialize
  super()

  @parent = nil
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



9
10
11
# File 'lib/trace_viz/trace_data/node.rb', line 9

def children
  @children
end

#parentObject

Returns the value of attribute parent.



8
9
10
# File 'lib/trace_viz/trace_data/node.rb', line 8

def parent
  @parent
end

Instance Method Details

#add_child(node) ⇒ Object



18
19
20
21
# File 'lib/trace_viz/trace_data/node.rb', line 18

def add_child(node)
  node.parent = self
  @children << node
end

#add_children(nodes) ⇒ Object



23
24
25
26
27
# File 'lib/trace_viz/trace_data/node.rb', line 23

def add_children(nodes)
  nodes.each do |node|
    add_child(node)
  end
end

#to_hObject



29
30
31
32
33
34
35
36
# File 'lib/trace_viz/trace_data/node.rb', line 29

def to_h
  super.merge(
    {
      parent: parent&.to_s,
      children: children.map(&:to_h),
    },
  )
end