Class: Neo4j::Core::Rels::Traverser
- Inherits:
-
Object
- Object
- Neo4j::Core::Rels::Traverser
- 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.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#between(between) ⇒ Object
(also: #to_other)
Specifies that we only want relationship to the given node.
-
#both ⇒ Object
Specifies that we want both incoming and outgoing direction.
-
#del ⇒ Object
Deletes all the relationships.
-
#each ⇒ Object
Implements the Ruby Enumerable mixin.
-
#empty? ⇒ true, false
If there are no relationships of specified dir and type(s).
-
#incoming ⇒ Object
Specifies that we only want incoming relationships.
-
#initialize(node, types, dir = :both) ⇒ Traverser
constructor
Called from Neo4j::Core::Node#rels.
-
#iterator ⇒ Object
The Java Iterator.
-
#match_between?(rel) ⇒ true, false
True if it match the specified other node.
-
#outgoing ⇒ Object
Specifies that only outgoing relationships is wanted.
- #to_s ⇒ Object
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
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
13 14 15 |
# File 'lib/neo4j-core/rels/traverser.rb', line 13 def dir @dir end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
12 13 14 |
# File 'lib/neo4j-core/rels/traverser.rb', line 12 def node @node end |
#types ⇒ Object (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
61 62 63 64 |
# File 'lib/neo4j-core/rels/traverser.rb', line 61 def between(between) @between = between self end |
#both ⇒ Object
Specifies that we want both incoming and outgoing direction
76 77 78 79 |
# File 'lib/neo4j-core/rels/traverser.rb', line 76 def both @dir = :both self end |
#del ⇒ Object
Deletes all the relationships
69 70 71 |
# File 'lib/neo4j-core/rels/traverser.rb', line 69 def del each { |rel| rel.del } end |
#each ⇒ Object
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).
35 36 37 |
# File 'lib/neo4j-core/rels/traverser.rb', line 35 def empty? first == nil end |
#incoming ⇒ Object
Specifies that we only want incoming relationships
83 84 85 86 |
# File 'lib/neo4j-core/rels/traverser.rb', line 83 def incoming @dir = :incoming self end |
#iterator ⇒ Object
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.
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 |
#outgoing ⇒ Object
Specifies that only outgoing relationships is wanted.
90 91 92 93 |
# File 'lib/neo4j-core/rels/traverser.rb', line 90 def outgoing @dir = :outgoing self end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/neo4j-core/rels/traverser.rb', line 23 def to_s "#{self.class} [types: #{@types.join(',')} dir:#{@dir}]" end |