Method: Cbt::Diagram#process!

Defined in:
lib/cbt/diagram.rb

#process!Object



6
7
8
9
10
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
41
42
43
44
45
46
47
# File 'lib/cbt/diagram.rb', line 6

def process!
  g = Rviz::Graph.new
  g.set('dpi', '300')
  g.set('rankdir', 'LR')
  
  # for each components, create a node of graphviz
  @components.each do |cname, c|
    if @options[:tag] and @options[:tag].size > 0
      next unless @options[:tag].include? c.tag
    end

    # parse source file, add relationship
    c.modules.each do |mname, m|
      rec_name = m.name
      attrs = self.tags(c.tag)
      g.add_record(rec_name, attrs)
      g.node(rec_name).add_row(cname + '/' + m.name, true)
      g.add_edge(rec_name, 'f1', m.super_class, nil, {label: 'inherit', arrowhead: "odiamond"}) if m.super_class 

      # parse the file
      comp_dir = c.dir(@options[:components_dir])
      lua_file = m.path([comp_dir], 'debug')
      File.open(lua_file).each do |line|
        next if line =~ /no_erd/
        line.chomp!
        if /function\s#{m.name}\:/ =~ line
          func = line.gsub(/^.*function\s#{m.name}\:/, '')
          func.gsub!(/#.*$/, '')
          g.node(rec_name).add_row('+' + func, false) 
        end

        if /diagram\s*\-\>\s*/ =~ line
          link_to = line.gsub(/^.*diagram\s*\-\>\s*/, '')
          tgt, label = link_to.split(/\s+/, 2)
          g.add_edge(rec_name, 'f1', tgt, nil, {label: label})
        end
      end
    end
  end

  g.output
end