Sha256: e8b0bce0886db4a7f4f89bd8016e7e27a20529b095b7739efb58affd053e84df

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'rviz'

module Cbt
  class Diagram < App

    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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cbt-0.0.1 lib/cbt/diagram.rb