Class: Hiptest::ProjectGrapher

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/project_grapher.rb

Overview

Builds a graph based on calls and computes longest path from the root.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ ProjectGrapher

Returns a new instance of ProjectGrapher.



19
20
21
22
# File 'lib/hiptest-publisher/project_grapher.rb', line 19

def initialize(project)
  @project = project
  @graph = {}
end

Instance Attribute Details

#distance_indexObject (readonly)

Returns the value of attribute distance_index.



8
9
10
# File 'lib/hiptest-publisher/project_grapher.rb', line 8

def distance_index
  @distance_index
end

#graphObject (readonly)

Returns the value of attribute graph.



8
9
10
# File 'lib/hiptest-publisher/project_grapher.rb', line 8

def graph
  @graph
end

Class Method Details

.distances_index(project) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/hiptest-publisher/project_grapher.rb', line 10

def self.distances_index(project)
  instance = ProjectGrapher.new(project)
  instance.compute_graph
  instance.add_distances
  instance.index_by_distances

  return instance.distance_index
end

Instance Method Details

#add_distancesObject



29
30
31
# File 'lib/hiptest-publisher/project_grapher.rb', line 29

def add_distances
  add_node_weight(@graph[:root], [:root])
end

#compute_graphObject



24
25
26
27
# File 'lib/hiptest-publisher/project_grapher.rb', line 24

def compute_graph
  add_nodes
  add_root
end

#index_by_distancesObject



33
34
35
36
37
38
# File 'lib/hiptest-publisher/project_grapher.rb', line 33

def index_by_distances
  @distance_index = Hash.new { |hash, key| hash[key] = [] }
  @graph.each_value do |value|
    @distance_index[value[:distance_from_root]] << value[:item] if value[:item]
  end
end