class Neography::RelationshipTraverser

Public Class Methods

new(node, types, direction) click to toggle source
# File lib/neography/relationship_traverser.rb, line 5
def initialize(node, types, direction)
  @node      = node
  @types     = [types]
  @direction = direction
end

Public Instance Methods

both() click to toggle source
# File lib/neography/relationship_traverser.rb, line 64
def both
  @direction = :both
  self
end
del() click to toggle source
# File lib/neography/relationship_traverser.rb, line 56
def del
  each { |rel| @node.neo_server.delete_relationship(rel) }
end
each() { |rel| ... } click to toggle source
# 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?() click to toggle source
# File lib/neography/relationship_traverser.rb, line 31
def empty?
  first == nil
end
incoming() click to toggle source
# File lib/neography/relationship_traverser.rb, line 69
def incoming
  @direction = :incoming
  self
end
iterator() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/neography/relationship_traverser.rb, line 74
def outgoing
  @direction = :outgoing
  self
end
size() click to toggle source
# File lib/neography/relationship_traverser.rb, line 60
def size
  [*self].size
end
to_other(to_other) click to toggle source
# File lib/neography/relationship_traverser.rb, line 51
def to_other(to_other)
  @to_other = to_other
  self
end
to_s() click to toggle source
# 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