class DepViz

Public Class Methods

new(s='', fields: %w(label shape), delimiter: ' click to toggle source
Calls superclass method
# File lib/depviz.rb, line 104
  def initialize(s='',  fields: %w(label shape), delimiter: ' # ', 
                 root: 'platform', style: nil, 
                 debug: false, fill: '#ccffcc', stroke: '#999999', 
                 text_color: '#330055')
    
    @style, @root, @debug = style, root, debug
    @header = "
<?polyrex schema='items[type]/item[label]' delimiter =' # '?>
type: digraph

    "
    if s.length > 0 then 
      
      if s =~ /<?depviz / then
          
        raw_dv = s.clone
        s2 = raw_dv.slice!(/<\?depviz [^>]+\?>/)

        # attributes being sought =>  root fields delimiter id
        attributes = Shellwords::shellwords(s).map {|x| key, 
                          value = x.split(/=/, 2); [key.to_sym, value]}.to_h
        
        h = {
          fields: fields.join(', '), 
          delimiter: delimiter
        }.merge attributes          

        s = if h[:root] then
          "\n\n" + h[:root] + "\n" + 
            raw_dv.strip.lines.map {|line| '  ' + line}.join
        else
          raw_dv
        end
        
        delimiter = h[:delimiter]
        fields = h[:fields].split(/ *, */)

      end            
    
      @s = tree = DependencyBuilder.new(s).to_s          
      s3 = @root ? (@root + "\n" + tree.lines.map {|x| '  ' + x}.join) : tree
      @pxg = super(@header + s3, style: @style)      
      
    end
    

  end

Public Instance Methods

count() click to toggle source
# File lib/depviz.rb, line 152
def count()
  return 0 unless @s
  child_nodes.length
end
item(name) click to toggle source
# File lib/depviz.rb, line 157
def item(name)
  
  puts 'inside DepViz::item for ' + name.inspect if @debug
  puts '_@s : ' + @s.inspect if @debug
  Item.new @s, root: @root, name: name, debug: @debug
  
end
nodes() click to toggle source
# File lib/depviz.rb, line 165
def nodes()
  
  child_nodes.map {|x| x.name}.uniq
  
end
read(s) click to toggle source
# File lib/depviz.rb, line 171
def read(s)
  
  @s = s
  s2 = @root ? @root + "\n" + s.lines.map {|x| '  ' + x}.join : s
  @pxg = PxGraphViz.new(@header + s2, style: @style)
  
end
to_doc() click to toggle source
# File lib/depviz.rb, line 179
def to_doc()
  Rexle.new(LineTree.new(@s, root: @root).to_xml).root.elements.first
end
to_s() click to toggle source
# File lib/depviz.rb, line 183
def to_s()
  @s
end
to_xml() click to toggle source
# File lib/depviz.rb, line 187
def to_xml()
  to_doc.xml
end

Private Instance Methods

child_nodes() click to toggle source
# File lib/depviz.rb, line 193
def child_nodes()
  to_doc.root.xpath('//*')
end
default_stylesheet() click to toggle source
# File lib/depviz.rb, line 197
  def default_stylesheet()

<<STYLE
  node { 
    color: #ddaa66; 
    fillcolor: #447722;
    fontcolor: #ffeecc; 
    fontname: 'Trebuchet MS';
    fontsize: 10; 
    margin: 0.1;
    penwidth: 1.3; 
    style: filled;
  }
  
  a node {
    color: #0011ee;   
  }

  edge {
    arrowsize: 0.9;
    color: #666; 
    fontcolor: #444444; 
    fontname: Verdana; 
    fontsize: 8; 
    dir: forward;
    weight: 1;
  }
STYLE

  end