Class: TTY::Tree::DirectoryRenderer

Inherits:
Object
  • Object
show all
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

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, options = {})
  @nodes  = nodes
  @indent = options.fetch(:indent, 4)
  @pipe_mark  = MARKERS[:unicode][:pipe] + ' ' * [@indent - 1, 0].max
  @space_mark = ' ' * @indent
end

Instance Method Details

#renderObject



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