Sha256: 176d5f43331afae45be7c882610fff75b0953f568e74bb48b4a4b727ca1819ad

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

module CognitiveDistance::Transforms
  class CallTreeToModuleBoundaryGraph
    def self.transform tree
      new.transform(tree)
    end

    def transform tree
      CognitiveDistance::Structures::Graph.new.tap do |graph|
        link_nodes graph, tree.to_a
      end
    end

  private
    def link_nodes graph, node_arr, prefix=""
      node_arr.each do |parent, children|
        link_boundary_crossings graph, parent, children, "#{prefix}\t"
      end
   end

    def link_boundary_crossings graph, parent, children, prefix=""
      children.each do |(child, _)|
        if !parent.context.equal?(child.context)
          graph.link parent, child
        end
      end
      link_nodes graph, children, prefix
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cognitive_distance-0.0.1.pre lib/cognitive_distance/transforms/call_tree_to_module_boundary_graph.rb