Class: Spoom::FileTree::Printer

Inherits:
Visitor
  • Object
show all
Defined in:
lib/spoom/file_tree.rb

Overview

An internal class used to print a FileTree

See ‘FileTree#print`

Instance Method Summary collapse

Methods inherited from Visitor

#visit_nodes, #visit_tree

Constructor Details

#initialize(strictnesses, out: $stdout, colors: true) ⇒ Printer

: (Hash[FileTree::Node, String?] strictnesses, ?out: (IO | StringIO), ?colors: bool) -> void



203
204
205
206
207
208
# File 'lib/spoom/file_tree.rb', line 203

def initialize(strictnesses, out: $stdout, colors: true)
  super()
  @strictnesses = strictnesses
  @colors = colors
  @printer = Spoom::Printer.new(out: out, colors: colors) #: Spoom::Printer
end

Instance Method Details

#visit_node(node) ⇒ Object

: (FileTree::Node node) -> void



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/spoom/file_tree.rb', line 212

def visit_node(node)
  @printer.printt
  if node.children.empty?
    strictness = @strictnesses[node]
    if @colors
      @printer.print_colored(node.name, strictness_color(strictness))
    elsif strictness
      @printer.print("#{node.name} (#{strictness})")
    else
      @printer.print(node.name.to_s)
    end
    @printer.print("\n")
  else
    @printer.print_colored(node.name, Color::BLUE)
    @printer.print("/")
    @printer.printn
    @printer.indent
    super
    @printer.dedent
  end
end