class Neography::NodeTraverser
Attributes
depth[RW]
filter[RW]
order[RW]
prune[RW]
relationships[RW]
uniqueness[RW]
Public Class Methods
new(from, types = nil, dir = "all" )
click to toggle source
# File lib/neography/node_traverser.rb, line 7 def initialize(from, types = nil, dir = "all" ) @from = from @order = "depth first" @uniqueness = "none" @relationships = Array.new types.each do |type| @relationships << {"type" => type.to_s, "direction" => dir.to_s } end unless types.nil? end
Public Instance Methods
<<(other_node)
click to toggle source
# File lib/neography/node_traverser.rb, line 17 def <<(other_node) create(other_node) self end
[](index)
click to toggle source
# File lib/neography/node_traverser.rb, line 97 def [](index) each_with_index {|node,i| break node if index == i} end
both(type)
click to toggle source
# File lib/neography/node_traverser.rb, line 36 def both(type) @relationships << {"type" => type.to_s, "direction" => "all"} self end
create(other_node)
click to toggle source
# File lib/neography/node_traverser.rb, line 22 def create(other_node) case @relationships.first["direction"] when "outgoing", "out" rel = Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], @from, other_node)) when "incoming", "in" rel = Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], other_node, @from)) else rel = Array.new rel << Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], @from, other_node)) rel << Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], other_node, @from)) end rel end
each() { |node| ... }
click to toggle source
# File lib/neography/node_traverser.rb, line 105 def each iterator.each do |i| node = @from.class.new(i) node.neo_server = @from.neo_server yield node end end
empty?()
click to toggle source
# File lib/neography/node_traverser.rb, line 101 def empty? first == nil end
include_start_node()
click to toggle source
# File lib/neography/node_traverser.rb, line 83 def include_start_node @filter = { "language" => "builtin", "name" => "all" } self end
incoming(type)
click to toggle source
# File lib/neography/node_traverser.rb, line 46 def incoming(type) @relationships << {"type" => type.to_s, "direction" => "in"} self end
iterator()
click to toggle source
# File lib/neography/node_traverser.rb, line 113 def iterator options = { "order" => @order, "uniqueness" => @uniqueness, "relationships" => @relationships } options["prune evaluator"] = @prune unless @prune.nil? options["return filter"] = @filter unless @filter.nil? options["depth"] = @depth unless @depth.nil? if @relationships[0]["type"].empty? rels = @from.neo_server.get_node_relationships(@from, @relationships[0]["direction"]) || [] case @relationships[0]["direction"] when "in" rels.collect { |r| @from.neo_server.get_node(r["start"]) } #.uniq when "out" rels.collect { |r| @from.neo_server.get_node(r["end"]) } #.uniq else rels.collect { |r| if @from.neo_id == r["start"].split('/').last @from.neo_server.get_node(r["end"]) else @from.neo_server.get_node(r["start"]) end } #.uniq end else @from.neo_server.traverse(@from, "nodes", options) end end
outgoing(type)
click to toggle source
# File lib/neography/node_traverser.rb, line 41 def outgoing(type) @relationships << {"type" => type.to_s, "direction" => "out"} self end
size()
click to toggle source
# File lib/neography/node_traverser.rb, line 91 def size [*self].size end
Also aliased as: length