1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
|
# File 'lib/xiki/tree.rb', line 1718
def self.paths_to_tree paths
result = ""
stack = []
paths.sort.each do |path|
beginning_slash = path =~ /^\//
ending_slash = path =~ /\/$/
split = path.sub(/^\//, '').split('/')
split[0].sub! /^/, '/' if beginning_slash split[-1].sub! /$/, '/' if ending_slash
while(stack.size > 0 && stack != split[0..(stack.size - 1)])
stack.pop
end
indent = stack.length remainder = split[indent..-1]
remainder.each do |dir|
result << (" " * indent) + dir
result << "\n"
indent += 1
end
stack = split
end
self.add_pluses_and_minuses result
result
end
|