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.



132
133
134
135
136
# File 'lib/spoom/file_tree.rb', line 132

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.



121
122
123
# File 'lib/spoom/file_tree.rb', line 121

def tree
  @tree
end

Instance Method Details



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

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


171
172
173
# File 'lib/spoom/file_tree.rb', line 171

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


139
140
141
# File 'lib/spoom/file_tree.rb', line 139

def print_tree
  print_nodes(tree.roots)
end