Class: Clearly::Query::Graph
- Inherits:
-
Object
- Object
- Clearly::Query::Graph
- Defined in:
- lib/clearly/query/graph.rb
Overview
Stores a graph and provides methods to operate on the graph. Graph nodes are a hash, and one special key contains an array of child nodes.
Instance Attribute Summary collapse
-
#child_key ⇒ Object
readonly
name of the hash key that holds the child nodes.
-
#root_node ⇒ Object
readonly
root node.
Instance Method Summary collapse
-
#branches ⇒ Array
build an array that contains paths from the root to all leaves.
-
#initialize(root_node, child_key) ⇒ Clearly::Query::DepthFirstSearch
constructor
Create a new Graph.
Constructor Details
#initialize(root_node, child_key) ⇒ Clearly::Query::DepthFirstSearch
Create a new Graph.
18 19 20 21 22 23 24 25 26 |
# File 'lib/clearly/query/graph.rb', line 18 def initialize(root_node, child_key) @root_node = root_node @child_key = child_key @discovered_nodes = [] @paths = [] self end |
Instance Attribute Details
#child_key ⇒ Object (readonly)
name of the hash key that holds the child nodes
12 13 14 |
# File 'lib/clearly/query/graph.rb', line 12 def child_key @child_key end |
#root_node ⇒ Object (readonly)
root node
9 10 11 |
# File 'lib/clearly/query/graph.rb', line 9 def root_node @root_node end |
Instance Method Details
#branches ⇒ Array
build an array that contains paths from the root to all leaves
30 31 32 33 34 35 |
# File 'lib/clearly/query/graph.rb', line 30 def branches if @discovered_nodes.blank? && @paths.blank? traverse_branches(@root_node, nil) end @paths end |