Sha256: 54c815daebb9869415e33ee8f7f63885484d6c24775617c74b3c7621b8dd29fe
Contents?: true
Size: 699 Bytes
Versions: 3
Compression:
Stored size: 699 Bytes
Contents
# frozen_string_literal: true module TTY class Tree # Render nodes as numbered list class NumberRenderer def initialize(nodes, options = {}) @indent = options.fetch(:indent, 4) @nodes = nodes @mark = ' ' * @indent end def render @nodes.each_with_index.reduce([]) do |acc, (node, i)| render_node(acc, node, i, @mark) end.join end private def render_node(acc, node, i, mark) acc << node.prefix.gsub(/:pipe|:space/, mark) unless node.root? acc << "#{node.level}.#{i} " end acc << node.name.to_s + "\n" end end # NumberRenderer end # Tree end # TTY
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tty-tree-0.4.0 | lib/tty/tree/number_renderer.rb |
tty-tree-0.3.0 | lib/tty/tree/number_renderer.rb |
tty-tree-0.2.0 | lib/tty/tree/number_renderer.rb |