Class: Spoom::FileTree::TreePrinter

Inherits:
Printer
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/spoom/file_tree.rb

Overview

An internal class used to print a FileTree

See `FileTree#print`

Instance Attribute Summary collapse

Attributes inherited from Printer

#out

Instance Method Summary collapse

Methods inherited from Printer

#colorize, #dedent, #indent, #print, #print_colored, #printl, #printn, #printt

Methods included from Colorize

#set_color

Constructor Details

#initialize(tree:, out: $stdout, show_strictness: true, colors: true, indent_level: 0) ⇒ TreePrinter

Returns a new instance of TreePrinter.


130
131
132
133
134
# File 'lib/spoom/file_tree.rb', line 130

def initialize(tree:, out: $stdout, show_strictness: true, colors: true, indent_level: 0)
  super(out: out, colors: colors, indent_level: indent_level)
  @tree = tree
  @show_strictness = show_strictness
end

Instance Attribute Details

#treeObject (readonly)

Returns the value of attribute tree.


119
120
121
# File 'lib/spoom/file_tree.rb', line 119

def tree
  @tree
end

Instance Method Details


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/spoom/file_tree.rb', line 142

def print_node(node)
  printt
  if node.children.empty?
    if @show_strictness
      strictness = node_strictness(node)
      if @colors
        print_colored(node.name, strictness_color(strictness))
      elsif strictness
        print("#{node.name} (#{strictness})")
      else
        print(node.name.to_s)
      end
    else
      print(node.name.to_s)
    end
    print("\n")
  else
    print_colored(node.name, Color::BLUE)
    print("/")
    printn
    indent
    print_nodes(node.children.values)
    dedent
  end
end

169
170
171
# File 'lib/spoom/file_tree.rb', line 169

def print_nodes(nodes)
  nodes.each { |node| print_node(node) }
end

137
138
139
# File 'lib/spoom/file_tree.rb', line 137

def print_tree
  print_nodes(tree.roots)
end