tree_uzuki 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/tree_uzuki +2 -2
- data/lib/tree/tree_render.rb +20 -24
- data/lib/tree/walker.rb +9 -12
- data/lib/tree.rb +3 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e479ff9ef2011dbdbd9e32af736ff736d56659e6f8dc4904be6aa90bd1462954
|
4
|
+
data.tar.gz: 3a11a45e98d716e693b0206ad26a9cd160c55bf50739686683d8f25804c66277
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb1d4de9ad758955c5f44852054c93f36b119fc8ccc69529d53933dc903b23a67261cd9107942b4f4cd08b2feb1c694640e77f5127a5773317586dd4fdb6f7ae
|
7
|
+
data.tar.gz: f5d9f38dbe226f551173799c7c6350db9d0b46c6f7d2974549b28f12aebcc1cb0e518a49187513394469d8224a01cb46de5d81bc94d47aa4f97b2d70a180625d
|
data/bin/tree_uzuki
CHANGED
data/lib/tree/tree_render.rb
CHANGED
@@ -1,39 +1,35 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
-
|
4
3
|
class Tree_render
|
5
|
-
def
|
4
|
+
def rendering(tree_data,root)
|
6
5
|
final_hash = {}
|
7
6
|
branch = "├── "
|
8
7
|
pipe = "│ "
|
9
8
|
turn = "└── "
|
10
9
|
space = " "
|
11
|
-
|
12
10
|
tree_data.sort!
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
leaf_level = tree_data[i].to_s.count('/') - root.to_s.count('/')
|
17
|
-
final_hash[i] = Array.new
|
11
|
+
tree_data.reverse_each do |i|
|
12
|
+
leaf_level = i.to_s.count('/') - root.to_s.count('/')
|
13
|
+
final_hash[tree_data.index(i)] = Array.new
|
18
14
|
if leaf_level == 1
|
19
|
-
final_hash[i] << branch
|
20
|
-
final_hash[i] << File.basename(
|
15
|
+
final_hash[tree_data.index(i)] << branch
|
16
|
+
final_hash[tree_data.index(i)] << File.basename(i)
|
21
17
|
else
|
22
|
-
final_hash[i] << space
|
23
|
-
(leaf_level-2).times {final_hash[i] << space}
|
24
|
-
final_hash[i] << branch
|
25
|
-
final_hash[i] << File.basename(
|
18
|
+
final_hash[tree_data.index(i)] << space
|
19
|
+
(leaf_level-2).times {final_hash[tree_data.index(i)] << space}
|
20
|
+
final_hash[tree_data.index(i)] << branch
|
21
|
+
final_hash[tree_data.index(i)] << File.basename(i)
|
26
22
|
end
|
27
|
-
|
28
|
-
next if final_hash[i+1] == nil
|
29
|
-
if final_hash[i][index] == space && (final_hash[i+1][index] == branch ||
|
30
|
-
|
31
|
-
|
32
|
-
final_hash[i][index] = pipe
|
33
|
-
elsif final_hash[i][index] == branch && (final_hash[i+1][index] != branch &&
|
34
|
-
|
35
|
-
|
36
|
-
final_hash[i][index] = turn
|
23
|
+
final_hash.each_with_index do |obj ,index|
|
24
|
+
next if final_hash[tree_data.index(i)+1] == nil
|
25
|
+
if final_hash[tree_data.index(i)][index] == space && (final_hash[tree_data.index(i)+1][index] == branch ||
|
26
|
+
final_hash[tree_data.index(i)+1][index] == pipe ||
|
27
|
+
final_hash[tree_data.index(i)+1][index] == turn)
|
28
|
+
final_hash[tree_data.index(i)][index] = pipe
|
29
|
+
elsif final_hash[tree_data.index(i)][index] == branch && (final_hash[tree_data.index(i)+1][index] != branch &&
|
30
|
+
final_hash[tree_data.index(i)+1][index] != pipe &&
|
31
|
+
final_hash[tree_data.index(i)+1][index] != turn)
|
32
|
+
final_hash[tree_data.index(i)][index] = turn
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
data/lib/tree/walker.rb
CHANGED
@@ -1,29 +1,26 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
-
|
4
3
|
class Walker
|
5
|
-
def
|
6
|
-
level += 1
|
4
|
+
def dir_walk (path_array, directories, files, tree_data)
|
7
5
|
folders_arr = []
|
8
|
-
|
9
|
-
if
|
6
|
+
path_array.each do |i|
|
7
|
+
if i.file?
|
10
8
|
files += 1
|
11
9
|
next
|
12
10
|
else
|
13
|
-
directories += 1
|
14
|
-
|
11
|
+
directories += 1
|
12
|
+
i.each_child do |dir|
|
15
13
|
folders_arr << dir
|
16
14
|
tree_data << dir
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
15
|
+
i = dir
|
16
|
+
end
|
17
|
+
end
|
20
18
|
end
|
21
19
|
if folders_arr.empty?
|
22
20
|
tree_data << "#{directories} directories, #{files} files"
|
23
21
|
return tree_data
|
24
|
-
|
25
22
|
else
|
26
|
-
|
23
|
+
dir_walk(folders_arr, directories, files, tree_data)
|
27
24
|
end
|
28
25
|
end
|
29
26
|
end
|
data/lib/tree.rb
CHANGED
@@ -3,8 +3,7 @@ require 'tree/walker'
|
|
3
3
|
require 'tree/tree_render'
|
4
4
|
|
5
5
|
class Tree
|
6
|
-
def self.
|
7
|
-
level = 0
|
6
|
+
def self.run(root = Dir.pwd)
|
8
7
|
tree_data = []
|
9
8
|
directories = 0
|
10
9
|
files = 0
|
@@ -14,10 +13,10 @@ class Tree
|
|
14
13
|
path_array << dir
|
15
14
|
tree_data << dir
|
16
15
|
end
|
17
|
-
tree_data = Walker.new.
|
16
|
+
tree_data = Walker.new.dir_walk(path_array, directories, files, tree_data)
|
18
17
|
files = tree_data.last
|
19
18
|
tree_data.pop
|
20
|
-
Tree_render.new.
|
19
|
+
Tree_render.new.rendering(tree_data, root)
|
21
20
|
puts files
|
22
21
|
end
|
23
22
|
end
|