Class: GraphManager

Inherits:
Object
  • Object
show all
Defined in:
lib/graph_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GraphManager

Returns a new instance of GraphManager.



5
6
7
8
9
10
11
12
13
# File 'lib/graph_manager.rb', line 5

def initialize(options)
  @stack   = ["start"]
  @edges   = []
  @options = options

  @g = GraphViz.new(:G, :type => :digraph)

  @g.add_node("start")
end

Instance Method Details

#add_edges(event) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graph_manager.rb', line 15

def add_edges(event)
  node = get_node_name(event)
  edge = [@stack.last, node]

  @stack << node

  return if @edges.include?(edge)

  @edges << edge
  @g.add_edge(*@edges.last)
end

#get_node_name(event) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/graph_manager.rb', line 27

def get_node_name(event)
  if @options[:show_path]
    "#{event.defined_class}##{event.method_id}\n#{event.path}".freeze
  else
    "#{event.defined_class}##{event.method_id}".freeze
  end
end

#node_countObject



39
40
41
# File 'lib/graph_manager.rb', line 39

def node_count
  @g.node_count
end

#output(*args) ⇒ Object



35
36
37
# File 'lib/graph_manager.rb', line 35

def output(*args)
  @g.output(*args)
end

#popObject



43
44
45
# File 'lib/graph_manager.rb', line 43

def pop
  @stack.pop
end