Class: TTY::Tree::DirectoryRenderer
- Inherits:
-
Object
- Object
- TTY::Tree::DirectoryRenderer
- Defined in:
- lib/tty/tree/directory_renderer.rb
Overview
Render nodes as files paths explorer
Constant Summary collapse
- MARKERS =
{ unicode: { branch: '├──', leaf: '└──', pipe: '│' }, ansi: { branch: '|--', leaf: '`--', pipe: '|' } }.freeze
Instance Method Summary collapse
-
#initialize(nodes, options = {}) ⇒ DirectoryRenderer
constructor
A new instance of DirectoryRenderer.
- #render ⇒ Object
Constructor Details
#initialize(nodes, options = {}) ⇒ DirectoryRenderer
Returns a new instance of DirectoryRenderer.
20 21 22 23 24 25 |
# File 'lib/tty/tree/directory_renderer.rb', line 20 def initialize(nodes, = {}) @nodes = nodes @indent = .fetch(:indent, 4) @pipe_mark = MARKERS[:unicode][:pipe] + ' ' * [@indent - 1, 0].max @space_mark = ' ' * @indent end |
Instance Method Details
#render ⇒ Object
27 28 29 30 31 |
# File 'lib/tty/tree/directory_renderer.rb', line 27 def render @nodes.reduce([]) do |acc, node| render_node(acc, node, @pipe_mark, @space_mark) end.join('') end |