class Spoom::FileTree

Build a file hierarchy from a set of file paths.

def add_path(path)

def add_path(path)
  parts = path.split("/")
  if path.empty? || parts.size == 1
    return @roots[path] ||= Node.new(parent: nil, name: path)
  end
  parent_path = T.must(parts[0...-1]).join("/")
  parent = add_path(parent_path)
  name = T.must(parts.last)
  parent.children[name] ||= Node.new(parent: parent, name: name)
end

def add_paths(paths)

def add_paths(paths)
  paths.each { |path| add_path(path) }
end

def initialize(paths = [])

def initialize(paths = [])
  @roots = T.let({}, T::Hash[String, Node])
  add_paths(paths)
end

def nodes

def nodes
  v = CollectNodes.new
  v.visit_tree(self)
  v.nodes
end

def nodes_strictness_scores(context)

def nodes_strictness_scores(context)
  v = CollectScores.new(context)
  v.visit_tree(self)
  v.scores
end

def nodes_strictnesses(context)

def nodes_strictnesses(context)
  v = CollectStrictnesses.new(context)
  v.visit_tree(self)
  v.strictnesses
end

def paths

def paths
  nodes.map(&:path)
end

def paths_strictness_scores(context)

def paths_strictness_scores(context)
  nodes_strictness_scores(context).map { |node, score| [node.path, score] }.to_h
end

def print(out: $stdout, colors: true)

def print(out: $stdout, colors: true)
  printer = Printer.new({}, out: out, colors: colors)
  printer.visit_tree(self)
end

def print_with_strictnesses(context, out: $stdout, colors: true)

def print_with_strictnesses(context, out: $stdout, colors: true)
  strictnesses = nodes_strictnesses(context)
  printer = Printer.new(strictnesses, out: out, colors: colors)
  printer.visit_tree(self)
end

def roots

def roots
  @roots.values
end