Class: Hiptest::ProjectGrapher
- Inherits:
-
Object
- Object
- Hiptest::ProjectGrapher
- 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
-
#distance_index ⇒ Object
readonly
Returns the value of attribute distance_index.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
Class Method Summary collapse
Instance Method Summary collapse
- #add_distances ⇒ Object
- #compute_graph ⇒ Object
- #index_by_distances ⇒ Object
-
#initialize(project) ⇒ ProjectGrapher
constructor
A new instance of ProjectGrapher.
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_index ⇒ Object (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 |
#graph ⇒ Object (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_distances ⇒ Object
29 30 31 |
# File 'lib/hiptest-publisher/project_grapher.rb', line 29 def add_distances add_node_weight(@graph[:root], [:root]) end |
#compute_graph ⇒ Object
24 25 26 27 |
# File 'lib/hiptest-publisher/project_grapher.rb', line 24 def compute_graph add_nodes add_root end |
#index_by_distances ⇒ Object
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 |