Class: DepViz::Item
- Inherits:
-
Object
- Object
- DepViz::Item
- Defined in:
- lib/depviz.rb
Instance Method Summary collapse
- #dependencies ⇒ Object
-
#initialize(s, root: nil, name: nil, debug: false) ⇒ Item
constructor
A new instance of Item.
-
#reverse_dependencies ⇒ Object
returns a DepViz document.
Constructor Details
Instance Method Details
#dependencies ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
returns a DepViz document
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# 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 |