Sha256: 542c2bb166fa59d110ef6f9079bfa6dff8e1da4953c8b9972d493ee72520ad22

Contents?: true

Size: 705 Bytes

Versions: 2

Compression:

Stored size: 705 Bytes

Contents

module Cadet
  class PathTraverser
    include Enumerable

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

    def each
      if @direction == :outgoing
        @nodes.each do |n|
          n.outgoing(@type).each do |o|
            yield o
          end
        end
      else
        @nodes.each do |n|
          n.incoming(@type).each do |o|
            yield o
          end
        end
      end
    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/path_traverser.rb
cadet-0.0.8-java lib/cadet/path_traverser.rb