class ReeRoda::BuildRoutingTree::RoutingTree

def find_by_value(tree: self, value: nil, type: :param, depth: 0)

def find_by_value(tree: self, value: nil, type: :param, depth: 0)
  return tree if tree.depth == depth && tree.values.include?(value)
  if tree.depth < depth
    res = tree
      .children
      .map { find_by_value(tree: _1, value: value, type: type, depth: depth) }
      .flatten
      .compact
    res.size > 1 ? res : res.first
  end
end