class DepViz::Item

Public Class Methods

new(s, root: nil, name: name, debug: false) click to toggle source
# File lib/depviz.rb, line 30
def initialize(s, root: nil, name: name, debug: false)
  @s, @root, @name, @debug = s, root, name, debug
end

Public Instance Methods

dependencies() click to toggle source
# File lib/depviz.rb, line 34
def dependencies()
  
  if @debug then
    puts 'inside DepViz::Item::dependencies'
    puts '@s: ' + @s.inspect
    puts '@root: ' + @root.inspect
  end
  
  a = LineTree.new(@s).to_doc.root.xpath('//' + @name)
  puts 'dep: a: ' + a.inspect if @debug
  
  enclose = ->(a) do
    a.length > 1 ? [a.first] << enclose.call(a[1..-1]) : a
  end
        
  a2 = a.map do |x|
    puts '  dependencies x: ' + x.inspect if @debug
    enclose.call x.backtrack.to_s.split('/')[1..-1]
  end
  
  puts 'a2: ' + a2.inspect if @debug
  
  # group the items in order to merge branches with the same parent
  a3 = a2.group_by(&:first)
  a4 = a3.map {|x| [x.first] + x.last.map(&:last)}      
        
  treeize = ->(obj, indent=-2) do

    if obj.is_a? Array then
      
      r = obj.map {|x| treeize.call(x, indent+1)}.join("\n")
      puts 'r: ' + r.inspect if @debug
      r

    else

      '  ' * indent + obj

    end
  end      
  
  s = treeize.call(a4)
  
  puts 'child s: ' + s.inspect if @debug

  dv3 = DepViz.new()
  dv3.read s
  dv3
  
end
reverse_dependencies() click to toggle source

returns a DepViz document

# File lib/depviz.rb, line 87
def reverse_dependencies()

  a = LineTree.new(@s, root: @root).to_doc.root.xpath('//' + @name)

  s = a.select {|x| x.has_elements? }\
      .map{|x| XmlToSliml.new(x).to_s }.join("\n")

  return DepViz.new if s.empty?
  
  dv3 = DepViz.new(root: nil)
  dv3.read s
  dv3
  
end