class Treely::Tree

Public Class Methods

new(source) click to toggle source
# File lib/treely/tree.rb, line 3
def initialize(source)
  @style = Treely[:style]
  @contents = %{}
  treely source
end

Public Instance Methods

to_s() click to toggle source
# File lib/treely/tree.rb, line 9
def to_s
  @contents
end

Private Instance Methods

treely(source, *args) click to toggle source
# File lib/treely/tree.rb, line 15
def treely(source, *args)
  source.each.with_index do |item, index|
    @contents << args.map { |name| @style[name] }.join
    @contents << @style[index.zero? ? :dot : :bar]
    @contents << @style[:new_line]
    @contents << args.map { |name| @style[name] }.join
    @contents << @style[source[index.next] ? :branch : :last_branch]
    @contents << item.fetch(:name)
    @contents << @style[:new_line]

    if item.has_key?(:contents)
      treely item[:contents], *args, (source[index.next] ? :bar : :indent)
    end
  end
end