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