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.
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
#tree ⇒ Object (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
#print_node(node) ⇒ Object
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 |
#print_nodes(nodes) ⇒ Object
169 170 171 |
# File 'lib/spoom/file_tree.rb', line 169 def print_nodes(nodes) nodes.each { |node| print_node(node) } end |
#print_tree ⇒ Object
137 138 139 |
# File 'lib/spoom/file_tree.rb', line 137 def print_tree print_nodes(tree.roots) end |