class RGL::PathBuilder
Public Class Methods
new(source, parents_map)
click to toggle source
# File lib/rgl/path_builder.rb 5 def initialize(source, parents_map) 6 @source = source 7 @parents_map = parents_map 8 @paths = {} 9 end
Public Instance Methods
path(target)
click to toggle source
# File lib/rgl/path_builder.rb 11 def path(target) 12 if @paths.has_key?(target) 13 @paths[target] 14 else 15 @paths[target] = restore_path(target) 16 end 17 end
paths(targets)
click to toggle source
@return [Hash]
# File lib/rgl/path_builder.rb 20 def paths(targets) 21 paths_map = {} 22 23 targets.each do |target| 24 paths_map[target] = path(target) 25 end 26 27 paths_map 28 end
Private Instance Methods
restore_path(target)
click to toggle source
# File lib/rgl/path_builder.rb 32 def restore_path(target) 33 return [@source] if target == @source 34 35 parent = @parents_map[target] 36 path(parent) + [target] if parent 37 end