class TTY::Tree::DirectoryRenderer
Render nodes as files paths explorer
Constants
- MARKERS
Public Class Methods
new(nodes, options = {})
click to toggle source
# 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
Public Instance Methods
render()
click to toggle source
# 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
Private Instance Methods
render_node(acc, node, pipe_mark, space_mark)
click to toggle source
# File lib/tty/tree/directory_renderer.rb, line 35 def render_node(acc, node, pipe_mark, space_mark) acc << node.prefix.gsub(/:pipe/, pipe_mark).gsub(/:space/, space_mark) unless node.root? acc << MARKERS[:unicode][node.leaf? ? :leaf : :branch] acc << ' ' end acc << node.name.to_s + "\n" end