Class: Neo4j::Driver::Types::Path
- Inherits:
-
Object
- Object
- Neo4j::Driver::Types::Path
- Includes:
- Enumerable
- Defined in:
- lib/neo4j/driver/types/path.rb
Overview
Represents a Path in the Neo4j graph A path is a sequence of alternating nodes and relationships
Defined Under Namespace
Classes: Segment
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
Instance Method Summary collapse
-
#contains_node?(node) ⇒ Boolean
Check if the path contains the given node.
-
#contains_relationship?(relationship) ⇒ Boolean
Check if the path contains the given relationship.
-
#each(&block) ⇒ Object
Iterate over segments in the path Each segment represents a relationship and its start/end nodes.
-
#end ⇒ Object
(also: #end_node)
Returns the end node of the path.
-
#initialize(nodes, relationships, segments) ⇒ Path
constructor
A new instance of Path.
-
#length ⇒ Object
Returns the number of relationships in the path (number of segments).
-
#start ⇒ Object
(also: #start_node)
Returns the start node of the path.
Constructor Details
#initialize(nodes, relationships, segments) ⇒ Path
Returns a new instance of Path.
13 14 15 16 17 |
# File 'lib/neo4j/driver/types/path.rb', line 13 def initialize(nodes, relationships, segments) @nodes = nodes @relationships = relationships @segments = segments end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
11 12 13 |
# File 'lib/neo4j/driver/types/path.rb', line 11 def nodes @nodes end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
11 12 13 |
# File 'lib/neo4j/driver/types/path.rb', line 11 def relationships @relationships end |
Instance Method Details
#contains_node?(node) ⇒ Boolean
Check if the path contains the given node
37 38 39 |
# File 'lib/neo4j/driver/types/path.rb', line 37 def contains_node?(node) @nodes.any? { |n| n.id == node.id } end |
#contains_relationship?(relationship) ⇒ Boolean
Check if the path contains the given relationship
42 43 44 |
# File 'lib/neo4j/driver/types/path.rb', line 42 def contains_relationship?(relationship) @relationships.any? { |r| r.id == relationship.id } end |
#each(&block) ⇒ Object
Iterate over segments in the path Each segment represents a relationship and its start/end nodes
48 49 50 |
# File 'lib/neo4j/driver/types/path.rb', line 48 def each(&block) @segments.each(&block) end |
#end ⇒ Object Also known as: end_node
Returns the end node of the path
26 27 28 |
# File 'lib/neo4j/driver/types/path.rb', line 26 def end @nodes.last end |
#length ⇒ Object
Returns the number of relationships in the path (number of segments)
32 33 34 |
# File 'lib/neo4j/driver/types/path.rb', line 32 def length @relationships.length end |
#start ⇒ Object Also known as: start_node
Returns the start node of the path
20 21 22 |
# File 'lib/neo4j/driver/types/path.rb', line 20 def start @nodes.first end |