Class: Neography::RelationshipTraverser
- Inherits:
-
Object
- Object
- Neography::RelationshipTraverser
- Includes:
- Enumerable
- Defined in:
- lib/neography/relationship_traverser.rb
Instance Method Summary collapse
- #both ⇒ Object
- #del ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #incoming ⇒ Object
-
#initialize(node, types, direction) ⇒ RelationshipTraverser
constructor
A new instance of RelationshipTraverser.
- #iterator ⇒ Object
- #match_to_other?(rel) ⇒ Boolean
- #outgoing ⇒ Object
- #size ⇒ Object
- #to_other(to_other) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(node, types, direction) ⇒ RelationshipTraverser
Returns a new instance of RelationshipTraverser.
5 6 7 8 9 |
# File 'lib/neography/relationship_traverser.rb', line 5 def initialize(node, types, direction) @node = node @types = [types] @direction = direction end |
Instance Method Details
#both ⇒ Object
64 65 66 67 |
# File 'lib/neography/relationship_traverser.rb', line 64 def both @direction = :both self end |
#del ⇒ Object
56 57 58 |
# File 'lib/neography/relationship_traverser.rb', line 56 def del each { |rel| @node.neo_server.delete_relationship(rel) } end |
#each ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/neography/relationship_traverser.rb', line 21 def each iterator.each do |i| rel = Neography::Relationship.new(i, @node.neo_server) rel.start_node = Neography::Node.load(rel.start_node, @node.neo_server) rel.end_node = Neography::Node.load(rel.end_node, @node.neo_server) yield rel if match_to_other?(rel) end end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/neography/relationship_traverser.rb', line 31 def empty? first == nil end |
#incoming ⇒ Object
69 70 71 72 |
# File 'lib/neography/relationship_traverser.rb', line 69 def incoming @direction = :incoming self end |
#iterator ⇒ Object
35 36 37 |
# File 'lib/neography/relationship_traverser.rb', line 35 def iterator Array(@node.neo_server.get_node_relationships(@node, @direction, @types)) end |
#match_to_other?(rel) ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/neography/relationship_traverser.rb', line 39 def match_to_other?(rel) if @to_other.nil? true elsif @direction == :outgoing rel.end_node == @to_other elsif @direction == :incoming rel.start_node == @to_other else rel.start_node == @to_other || rel.end_node == @to_other end end |
#outgoing ⇒ Object
74 75 76 77 |
# File 'lib/neography/relationship_traverser.rb', line 74 def outgoing @direction = :outgoing self end |
#size ⇒ Object
60 61 62 |
# File 'lib/neography/relationship_traverser.rb', line 60 def size [*self].size end |
#to_other(to_other) ⇒ Object
51 52 53 54 |
# File 'lib/neography/relationship_traverser.rb', line 51 def to_other(to_other) @to_other = to_other self end |
#to_s ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/neography/relationship_traverser.rb', line 11 def to_s if @types.size == 1 && !@types.empty? "#{self.class} [type: #{@type} dir:#{@direction}]" elsif !@types.empty? "#{self.class} [types: #{@types.join(',')} dir:#{@direction}]" else "#{self.class} [types: ANY dir:#{@direction}]" end end |