Module: Tree::PathAlgorithms

Includes:
KeyProperty, UpTreeAlgorithms
Defined in:
lib/modular_tree/algorithms.rb

Instance Method Summary collapse

Methods included from UpTreeAlgorithms

#ancestors, #depth, #parents

Methods included from BranchesProperty

#bare?, #branches, #each_branch

Methods included from NodeProperty

#node, #node_value

Methods included from KeyProperty

#key

Instance Method Details

#lookup(key) ⇒ Object

TODO

Raises:

  • (NotImplementedError)


337
# File 'lib/modular_tree/algorithms.rb', line 337

def lookup(key) = raise NotImplementedError

#pathObject



324
# File 'lib/modular_tree/algorithms.rb', line 324

def path = @path ||= ancestry[1..-1]&.map(&:key)&.join(separator) || ""

#search(*args, this: true, &block) ⇒ Object



327
328
329
330
331
332
333
334
# File 'lib/modular_tree/algorithms.rb', line 327

def search(*args, this: true, &block)
  matcher = Matcher.new(*args, &block)
  curr = this ? self : branch
  while curr
    return curr if matcher.match?(curr)
    curr = curr.branch
  end
end

#separatorObject



321
# File 'lib/modular_tree/algorithms.rb', line 321

def separator = @separator ||= parent&.separator || ::Tree.separator

#separator=(s) ⇒ Object



322
# File 'lib/modular_tree/algorithms.rb', line 322

def separator=(s) @separator = s end

#uidObject



325
# File 'lib/modular_tree/algorithms.rb', line 325

def uid() @uid ||= [parent&.uid, key].compact.join(separator) end