Class: Neo4j::Core::Rels::Traverser

Inherits:
Object
  • Object
show all
Includes:
Enumerable, ToJava
Defined in:
lib/neo4j-core/rels/traverser.rb

Overview

Traverse relationships of depth one from one node. This object is returned from the Neo4j::Node#rels method.

See Also:

  • Node#rels

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ToJava

dir_from_java, dir_to_java, type_to_java, types_to_java

Constructor Details

#initialize(node, types, dir = :both) ⇒ Traverser

Called from Neo4j::Core::Node#rels



17
18
19
20
21
# File 'lib/neo4j-core/rels/traverser.rb', line 17

def initialize(node, types, dir = :both)
  @node = node
  @types = types
  @dir = dir
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



13
14
15
# File 'lib/neo4j-core/rels/traverser.rb', line 13

def dir
  @dir
end

#nodeObject (readonly)

Returns the value of attribute node.



12
13
14
# File 'lib/neo4j-core/rels/traverser.rb', line 12

def node
  @node
end

#typesObject (readonly)

Returns the value of attribute types.



14
15
16
# File 'lib/neo4j-core/rels/traverser.rb', line 14

def types
  @types
end

Instance Method Details

#between(between) ⇒ Object Also known as: to_other

Specifies that we only want relationship to the given node

Parameters:

  • between (Neo4j::Node)

    a node or an object that implements the Neo4j::Core::Equal mixin

Returns:

  • self



61
62
63
64
# File 'lib/neo4j-core/rels/traverser.rb', line 61

def between(between)
  @between = between
  self
end

#bothObject

Specifies that we want both incoming and outgoing direction

Returns:

  • self



76
77
78
79
# File 'lib/neo4j-core/rels/traverser.rb', line 76

def both
  @dir = :both
  self
end

#delObject

Deletes all the relationships



69
70
71
# File 'lib/neo4j-core/rels/traverser.rb', line 69

def del
  each { |rel| rel.del }
end

#eachObject

Implements the Ruby Enumerable mixin



28
29
30
31
32
# File 'lib/neo4j-core/rels/traverser.rb', line 28

def each
  iterator.each do |rel|
    yield rel.wrapper if match_between?(rel)
  end
end

#empty?true, false

Returns if there are no relationships of specified dir and type(s).

Returns:

  • (true, false)

    if there are no relationships of specified dir and type(s)



35
36
37
# File 'lib/neo4j-core/rels/traverser.rb', line 35

def empty?
  first == nil
end

#incomingObject

Specifies that we only want incoming relationships

Returns:

  • self



83
84
85
86
# File 'lib/neo4j-core/rels/traverser.rb', line 83

def incoming
  @dir = :incoming
  self
end

#iteratorObject

Returns The Java Iterator.

Returns:

  • The Java Iterator



40
41
42
# File 'lib/neo4j-core/rels/traverser.rb', line 40

def iterator
  @node._rels(@dir, *@types)
end

#match_between?(rel) ⇒ true, false

Returns true if it match the specified other node.

Returns:

  • (true, false)

    true if it match the specified other node

See Also:



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/neo4j-core/rels/traverser.rb', line 46

def match_between?(rel)
  if @between.nil?
    true
  elsif @dir == :outgoing
    rel._end_node == @between
  elsif @dir == :incoming
    rel._start_node == @between
  else
    rel._start_node == @between || rel._end_node == @between
  end
end

#outgoingObject

Specifies that only outgoing relationships is wanted.

Returns:

  • self



90
91
92
93
# File 'lib/neo4j-core/rels/traverser.rb', line 90

def outgoing
  @dir = :outgoing
  self
end

#to_sObject



23
24
25
# File 'lib/neo4j-core/rels/traverser.rb', line 23

def to_s
  "#{self.class} [types: #{@types.join(',')} dir:#{@dir}]"
end