Sha256: 8d5e1efb22a222419101f348b48121d5e32088e6d018c09bb9d8d67f863180da

Contents?: true

Size: 908 Bytes

Versions: 25

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

# This module provides classes for the Makit gem.
module Makit
  class Tree
    def get_source_tree
      files = `git ls-files`.split("\n")
      tree = {}

      # Build a nested hash representing the file structure
      files.each do |file|
        parts = file.split("/")
        current = tree

        parts.each_with_index do |part, index|
          current[part] ||= (index == parts.length - 1 ? nil : {})
          current = current[part] unless current[part].nil?
        end
      end

      generate_tree_string(tree)
    end

    def generate_tree_string(tree, indent = "")
      result = ""
      tree.each do |key, value|
        if value.is_a?(Hash)
          result << "#{indent}#{key}/\n"
          result << generate_tree_string(value, "#{indent}  ")
        else
          result << "#{indent}#{key}\n"
        end
      end
      result
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
makit-0.0.57 lib/makit/tree.rb
makit-0.0.53 lib/makit/tree.rb
makit-0.0.52 lib/makit/tree.rb
makit-0.0.51 lib/makit/tree.rb
makit-0.0.50 lib/makit/tree.rb
makit-0.0.49 lib/makit/tree.rb
makit-0.0.47 lib/makit/tree.rb
makit-0.0.46 lib/makit/tree.rb
makit-0.0.45 lib/makit/tree.rb
makit-0.0.44 lib/makit/tree.rb
makit-0.0.42 lib/makit/tree.rb
makit-0.0.41 lib/makit/tree.rb
makit-0.0.35 lib/makit/tree.rb
makit-0.0.34 lib/makit/tree.rb
makit-0.0.33 lib/makit/tree.rb
makit-0.0.32 lib/makit/tree.rb
makit-0.0.31 lib/makit/tree.rb
makit-0.0.30 lib/makit/tree.rb
makit-0.0.29 lib/makit/tree.rb
makit-0.0.28 lib/makit/tree.rb