Sha256: 813b4f3c5cea3e7a5d22a9fbb5e9e67c97904e158cc1c25d275380dbb2493ec4

Contents?: true

Size: 675 Bytes

Versions: 2

Compression:

Stored size: 675 Bytes

Contents

module Cadet
  class NodeTraverser
    include Enumerable

    def initialize(node, direction, type)
      @node = node
      @type = type
      @direction = direction
    end

    def each
      @node.each_relationship(@direction, @type) do |rel|
        yield rel.get_other_node(@node)
      end
    end

    def << (othernode)
      @direction == :outgoing ? @node.create_outgoing(othernode, @type) : othernode.create_outgoing(@node, @type)
    end

    def outgoing(type)
      PathTraverser.new to_a, :outgoing, type
    end
    def incoming(type)
      PathTraverser.new to_a, :incoming, type
    end

    def ==(other)
      self.to_a == other.to_a
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cadet-0.0.9-java lib/cadet/node_traverser.rb
cadet-0.0.8-java lib/cadet/node_traverser.rb