Class: Spoom::FileTree::TreePrinter
- 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
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Attributes inherited from Printer
Instance Method Summary collapse
-
#initialize(tree:, out: $stdout, show_strictness: true, colors: true, indent_level: 0) ⇒ TreePrinter
constructor
A new instance of TreePrinter.
- #print_node(node) ⇒ Object
- #print_nodes(nodes) ⇒ Object
- #print_tree ⇒ Object
Methods inherited from Printer
#colorize, #dedent, #indent, #print, #print_colored, #printl, #printn, #printt
Methods included from Colorize
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
#tree ⇒ Object (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
#print_node(node) ⇒ Object
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 |
#print_nodes(nodes) ⇒ Object
171 172 173 |
# File 'lib/spoom/file_tree.rb', line 171 def print_nodes(nodes) nodes.each { |node| print_node(node) } end |
#print_tree ⇒ Object
139 140 141 |
# File 'lib/spoom/file_tree.rb', line 139 def print_tree print_nodes(tree.roots) end |