Class: Solidarity::Graph
- Inherits:
-
Object
- Object
- Solidarity::Graph
- Defined in:
- lib/solidarity/graph.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Class Method Summary collapse
Instance Method Summary collapse
- #find_node(name) ⇒ Object
- #incoming_edges(node_name) ⇒ Object
-
#initialize(ast_data) ⇒ Graph
constructor
A new instance of Graph.
- #outgoing_edges(node_name) ⇒ Object
Constructor Details
#initialize(ast_data) ⇒ Graph
Returns a new instance of Graph.
5 6 7 8 9 10 |
# File 'lib/solidarity/graph.rb', line 5 def initialize(ast_data) @nodes = [] @edges = [] initialize_from_ast_data(ast_data) end |
Instance Attribute Details
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
3 4 5 |
# File 'lib/solidarity/graph.rb', line 3 def edges @edges end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
3 4 5 |
# File 'lib/solidarity/graph.rb', line 3 def nodes @nodes end |
Class Method Details
.from_ast_data(ast_data) ⇒ Object
12 13 14 |
# File 'lib/solidarity/graph.rb', line 12 def self.from_ast_data(ast_data) new(ast_data) end |
Instance Method Details
#find_node(name) ⇒ Object
16 17 18 |
# File 'lib/solidarity/graph.rb', line 16 def find_node(name) @nodes.find { |node| node.name == name } end |
#incoming_edges(node_name) ⇒ Object
24 25 26 |
# File 'lib/solidarity/graph.rb', line 24 def incoming_edges(node_name) @edges.select { |edge| edge.target == node_name } end |
#outgoing_edges(node_name) ⇒ Object
20 21 22 |
# File 'lib/solidarity/graph.rb', line 20 def outgoing_edges(node_name) @edges.select { |edge| edge.source == node_name } end |