Class: Neo4j::Driver::Types::Path

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nodesObject (readonly)

Returns the value of attribute nodes.



11
12
13
# File 'lib/neo4j/driver/types/path.rb', line 11

def nodes
  @nodes
end

#relationshipsObject (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


42
43
44
# File 'lib/neo4j/driver/types/path.rb', line 42

def contains_relationship?(relationship)
  @relationships.any? { |r| r.id == relationship.id }
end

#eachObject

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(&)
  @segments.each(&)
end

#endObject 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

#lengthObject

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

#startObject 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