Class: RailsGraph::Graph::Graph
- Inherits:
-
Object
- Object
- RailsGraph::Graph::Graph
- Defined in:
- lib/rails_graph/graph/graph.rb
Instance Method Summary collapse
- #add_node(node) ⇒ Object
- #add_relationship(relationship) ⇒ Object
- #as_json(_options = nil) ⇒ Object
-
#initialize(nodes: {}, relationships: {}) ⇒ Graph
constructor
A new instance of Graph.
- #node(identifier) ⇒ Object
- #nodes ⇒ Object
- #relationship(identifier) ⇒ Object
- #relationships ⇒ Object
Constructor Details
#initialize(nodes: {}, relationships: {}) ⇒ Graph
Returns a new instance of Graph.
6 7 8 9 |
# File 'lib/rails_graph/graph/graph.rb', line 6 def initialize(nodes: {}, relationships: {}) @nodes = nodes @relationships = relationships end |
Instance Method Details
#add_node(node) ⇒ Object
11 12 13 |
# File 'lib/rails_graph/graph/graph.rb', line 11 def add_node(node) @nodes[node.identifier] = node end |
#add_relationship(relationship) ⇒ Object
23 24 25 |
# File 'lib/rails_graph/graph/graph.rb', line 23 def add_relationship(relationship) @relationships[relationship.identifier] = relationship end |
#as_json(_options = nil) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/rails_graph/graph/graph.rb', line 35 def as_json( = nil) { nodes: nodes, relationships: relationships } end |
#node(identifier) ⇒ Object
19 20 21 |
# File 'lib/rails_graph/graph/graph.rb', line 19 def node(identifier) @nodes[identifier] end |
#nodes ⇒ Object
15 16 17 |
# File 'lib/rails_graph/graph/graph.rb', line 15 def nodes @nodes.values end |
#relationship(identifier) ⇒ Object
31 32 33 |
# File 'lib/rails_graph/graph/graph.rb', line 31 def relationship(identifier) @relationships[identifier] end |
#relationships ⇒ Object
27 28 29 |
# File 'lib/rails_graph/graph/graph.rb', line 27 def relationships @relationships.values.flatten end |