Sha256: 3c7dfe3edd7c54552baf27ba55bb67b388845c6bc347a576740fb97887074986

Contents?: true

Size: 685 Bytes

Versions: 1

Compression:

Stored size: 685 Bytes

Contents

module RGL

    class PathBuilder

    def initialize(source, parents_map)
      @source      = source
      @parents_map = parents_map
      @paths       = {}
    end

    def path(target)
      if @paths.has_key?(target)
        @paths[target]
      else
        @paths[target] = restore_path(target)
      end
    end

    # @return [Hash]
    def paths(targets)
      paths_map = {}

      targets.each do |target|
        paths_map[target] = path(target)
      end

      paths_map
    end

    private

    def restore_path(target)
      return [@source] if target == @source

      parent = @parents_map[target]
      path(parent) + [target] if parent
    end

  end

end # RGL

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rgl-0.5.10 lib/rgl/path_builder.rb