Sha256: cfa52c2c70bdd3d04ccd946a3867a95e2ab72bab63d3e0a1c74c4b9a04ae12ca

Contents?: true

Size: 917 Bytes

Versions: 7

Compression:

Stored size: 917 Bytes

Contents

module Lapidarius
  class Tree
    CURVED = "└── "
    EMPTY = "    "
    NESTED = "├── "
    STRAIGHT = "│   "

    def initialize(gem, quiet = false)
      @gem = gem
      @quiet = quiet
      @out = []
    end

    def out
      return @out unless @out.empty?
      return count if @quiet
      @out.tap do |out|
        out << @gem
        recurse
        out << ""
        out << count
      end
    end

    def count
      "#{@gem.count} runtime, #{@gem.dev_count} development"
    end

    private def recurse(gem = @gem, prefix = "")
      last_index = gem.size - 1
      gem.each_with_index do |dep, i|
        pointer, preadd = branches(i == last_index)
        @out << "#{prefix}#{pointer}#{dep}"
        recurse(dep, "#{prefix}#{preadd}") if dep.size > 0
      end
    end
    
    private def branches(last)
      return [CURVED, EMPTY] if last
      [NESTED, STRAIGHT]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lapidarius-4.5.7 lib/lapidarius/tree.rb
lapidarius-4.5.6 lib/lapidarius/tree.rb
lapidarius-4.5.5 lib/lapidarius/tree.rb
lapidarius-4.4.4 lib/lapidarius/tree.rb
lapidarius-4.4.3 lib/lapidarius/tree.rb
lapidarius-4.4.2 lib/lapidarius/tree.rb
lapidarius-4.3.0 lib/lapidarius/tree.rb