Class: BlastRadius::Formatters::DotFormatter

Inherits:
Base
  • Object
show all
Defined in:
lib/blast_radius/formatters/dot_formatter.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BlastRadius::Formatters::Base

Instance Method Details

#format(root_node) ⇒ String

Format dependency tree as Graphviz DOT format

Parameters:

  • root_node (Node)

    root node of dependency tree

Returns:

  • (String)

    DOT format representation



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/blast_radius/formatters/dot_formatter.rb', line 11

def format(root_node)
  @edges = []
  @nodes = Set.new

  # Collect all nodes and edges
  collect_nodes_and_edges(root_node)

  # Build DOT output
  lines = [
    'digraph blast_radius {',
    '  rankdir=LR;',
    '  node [shape=box];',
    ''
  ]

  # Add nodes
  @nodes.each do |node_name|
    lines << %(  "#{node_name}";)
  end

  lines << ''

  # Add edges
  @edges.each do |edge|
    lines << edge
  end

  lines << '}'
  lines.join("\n")
end