Class: ActiveInteractionMapper::Output::Dot

Inherits:
Object
  • Object
show all
Defined in:
lib/active_interaction_mapper/output/dot.rb

Instance Method Summary collapse

Constructor Details

#initialize(folder_name: '', file_name: '', show_duplicated_path: false) ⇒ Dot

Returns a new instance of Dot.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_interaction_mapper/output/dot.rb', line 9

def initialize(folder_name:'', file_name:'', show_duplicated_path: false)
  d = DateTime.now
  d_string = d.strftime("%d%m%Y_%H%M%S")
  if folder_name.empty?
    @folder_name = "dir_#{d_string}"
  else
    @folder_name = "#{folder_name}"
  end
  if file_name.empty?
    @file_name = "img_#{d_string}.png"
  else
    @file_name = "#{file_name}_#{d_string}.png"
  end
  @show_duplicated_path = show_duplicated_path
  @edges = []
  @stack = []
  @graph = GraphViz.new('CodeMapper')

end

Instance Method Details

#doneObject



51
52
53
54
55
56
57
58
# File 'lib/active_interaction_mapper/output/dot.rb', line 51

def done
  full_path = "./tmp/#{@folder_name}/#{@file_name}"
  dirname = File.dirname(full_path)
  unless File.directory?(dirname)
    FileUtils.mkdir_p(dirname)
  end
  @graph.output( :png => full_path)
end

#pop(tp, normalized_class_name) ⇒ Object



47
48
49
# File 'lib/active_interaction_mapper/output/dot.rb', line 47

def pop(tp, normalized_class_name)
  @stack.pop
end

#push(tp, normalized_class_name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_interaction_mapper/output/dot.rb', line 29

def push(tp, normalized_class_name)
  node = @graph.add_node("#{normalized_class_name}")


  if @stack != []
    if !@show_duplicated_path
      if !@edges.include? "#{@stack.last};#{node}"
        @graph.add_edge(@stack.last,node)
        @edges << "#{@stack.last};#{node}"
      end
    else
      @graph.add_edge(@stack.last,node)
    end
  end

  @stack << node
end