Class: TTY::Tree::NumberRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/tree/number_renderer.rb

Overview

Render nodes as numbered list

Instance Method Summary collapse

Constructor Details

#initialize(nodes, options = {}) ⇒ NumberRenderer

Returns a new instance of NumberRenderer.



7
8
9
10
11
# File 'lib/tty/tree/number_renderer.rb', line 7

def initialize(nodes, options = {})
  @indent = options.fetch(:indent, 4)
  @nodes = nodes
  @mark = ' ' * @indent
end

Instance Method Details

#renderObject



13
14
15
16
17
# File 'lib/tty/tree/number_renderer.rb', line 13

def render
  @nodes.each_with_index.reduce([]) do |acc, (node, i)|
    render_node(acc, node, i, @mark)
  end.join
end