tree_slava 0.0.1 → 0.0.2
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/lib/data_tree/scanner.rb +9 -0
- data/lib/data_tree/tree.rb +46 -0
- data/lib/data_tree.rb +2 -55
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1f4fecaf46075ee7332ff4c9a4488eda846bf210bad6aba0929a475c0cbbf854
|
|
4
|
+
data.tar.gz: 67814b0d11f65458fbb629d8c79fe7b2d745af9d83049ebeaeff5df810605c85
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ccf2fe59eff0e4c3364fdb7071d2ec132b94fb92c56a4797b9352c98b3b801dc98a76b7073906dccf8e48cd8495f746194e2756e33b9c2a89bb536cca4cdeba
|
|
7
|
+
data.tar.gz: 956bca0de38f8da04c721da339641f8a0a4941b6c9826c113551a257e1711a0f78b50aac12c4ad7e435620f29e06feea02e1c9ccc5d830c8097756590b89cae3
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class Tree
|
|
2
|
+
def make_tree(path_arr, root)
|
|
3
|
+
tree_data = path_arr
|
|
4
|
+
tree_hash = {}
|
|
5
|
+
branch = '├── '
|
|
6
|
+
pipe = '│ '
|
|
7
|
+
leaf = '└── '
|
|
8
|
+
space = ' '
|
|
9
|
+
tree_data.sort!
|
|
10
|
+
i = tree_data.length
|
|
11
|
+
while i > -1
|
|
12
|
+
i -= 1
|
|
13
|
+
level = tree_data[i].to_s.count('/') - root.to_s.count('/')
|
|
14
|
+
tree_hash[i] = []
|
|
15
|
+
if level == 1
|
|
16
|
+
tree_hash[i] << branch
|
|
17
|
+
tree_hash[i] << File.basename(tree_data[i])
|
|
18
|
+
else
|
|
19
|
+
tree_hash[i] << space
|
|
20
|
+
(level - 2).times { tree_hash[i] << space }
|
|
21
|
+
tree_hash[i] << branch
|
|
22
|
+
tree_hash[i] << File.basename(tree_data[i])
|
|
23
|
+
end
|
|
24
|
+
(0..tree_hash[i].size).each do |index|
|
|
25
|
+
if tree_hash[i + 1].nil? && tree_hash[i][index] == branch
|
|
26
|
+
tree_hash[i][index] = leaf
|
|
27
|
+
elsif tree_hash[i + 1].nil?
|
|
28
|
+
next
|
|
29
|
+
elsif tree_hash[i][index] == space &&
|
|
30
|
+
(tree_hash[i + 1][index] == branch ||
|
|
31
|
+
tree_hash[i + 1][index] == pipe ||
|
|
32
|
+
tree_hash[i + 1][index] == leaf)
|
|
33
|
+
tree_hash[i][index] = pipe
|
|
34
|
+
elsif tree_hash[i][index] == branch &&
|
|
35
|
+
(tree_hash[i + 1][index] != branch &&
|
|
36
|
+
tree_hash[i + 1][index] != pipe &&
|
|
37
|
+
tree_hash[i + 1][index] != leaf)
|
|
38
|
+
tree_hash[i][index] = leaf
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
puts root
|
|
43
|
+
tree_hash = tree_hash.each.sort_by { |k, _v| k }
|
|
44
|
+
tree_hash.each { |_k, v| puts v.join }
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/data_tree.rb
CHANGED
|
@@ -1,58 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
def scan(root = Dir.pwd)
|
|
4
|
-
path_arr = []
|
|
5
|
-
root = Pathname.new(root)
|
|
6
|
-
root.find { |v| path_arr << v }
|
|
7
|
-
Tree.new.make_tree(path_arr, root)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
1
|
+
require_relative 'data_tree/scanner.rb'
|
|
2
|
+
require_relative 'data_tree/tree.rb'
|
|
10
3
|
|
|
11
|
-
class Tree
|
|
12
|
-
def make_tree(path_arr, root)
|
|
13
|
-
tree_data = path_arr
|
|
14
|
-
tree_hash = {}
|
|
15
|
-
branch = '├── '
|
|
16
|
-
pipe = '│ '
|
|
17
|
-
leaf = '└── '
|
|
18
|
-
space = ' '
|
|
19
|
-
tree_data.sort!
|
|
20
|
-
i = tree_data.length
|
|
21
|
-
while i > -1
|
|
22
|
-
i -= 1
|
|
23
|
-
level = tree_data[i].to_s.count('/') - root.to_s.count('/')
|
|
24
|
-
tree_hash[i] = []
|
|
25
|
-
if level == 1
|
|
26
|
-
tree_hash[i] << branch
|
|
27
|
-
tree_hash[i] << File.basename(tree_data[i])
|
|
28
|
-
else
|
|
29
|
-
tree_hash[i] << space
|
|
30
|
-
(level - 2).times { tree_hash[i] << space }
|
|
31
|
-
tree_hash[i] << branch
|
|
32
|
-
tree_hash[i] << File.basename(tree_data[i])
|
|
33
|
-
end
|
|
34
|
-
(0..tree_hash[i].size).each do |index|
|
|
35
|
-
if tree_hash[i + 1].nil? && tree_hash[i][index] == branch
|
|
36
|
-
tree_hash[i][index] = leaf
|
|
37
|
-
elsif tree_hash[i + 1].nil?
|
|
38
|
-
next
|
|
39
|
-
elsif tree_hash[i][index] == space &&
|
|
40
|
-
(tree_hash[i + 1][index] == branch ||
|
|
41
|
-
tree_hash[i + 1][index] == pipe ||
|
|
42
|
-
tree_hash[i + 1][index] == leaf)
|
|
43
|
-
tree_hash[i][index] = pipe
|
|
44
|
-
elsif tree_hash[i][index] == branch &&
|
|
45
|
-
(tree_hash[i + 1][index] != branch &&
|
|
46
|
-
tree_hash[i + 1][index] != pipe &&
|
|
47
|
-
tree_hash[i + 1][index] != leaf)
|
|
48
|
-
tree_hash[i][index] = leaf
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
puts root
|
|
53
|
-
tree_hash = tree_hash.each.sort_by { |k, _v| k }
|
|
54
|
-
tree_hash.each { |_k, v| puts v.join }
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
4
|
tree = Scanner.new
|
|
58
5
|
tree.scan
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tree_slava
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- somestyl3
|
|
@@ -17,7 +17,9 @@ extensions: []
|
|
|
17
17
|
extra_rdoc_files: []
|
|
18
18
|
files:
|
|
19
19
|
- lib/data_tree.rb
|
|
20
|
-
|
|
20
|
+
- lib/data_tree/scanner.rb
|
|
21
|
+
- lib/data_tree/tree.rb
|
|
22
|
+
homepage: https://rubygems.org/gems/tree_slava
|
|
21
23
|
licenses:
|
|
22
24
|
- MIT
|
|
23
25
|
metadata: {}
|