tree_graph 0.2.1 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/README.md +3 -1
- data/lib/tree_graph/version.rb +1 -1
- data/lib/tree_graph.rb +31 -7
- data/tree_graph.gemspec +2 -2
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 549de5663f06ffc375593a6fd2822f7ee880d836a4d0b8be15ad45e2b069ca48
|
4
|
+
data.tar.gz: 29a53608756a4aa918af5013926acb89c4134001999cede4ae902e8c0d0dea05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ab51ef607180e7d67040c524b4a427df610f0b8951916717d10c0dde111a3e45bb8c14f28204809f5cabbf7f9d47add6d2e85838e455319972f1d4885084699
|
7
|
+
data.tar.gz: e156f4b085477285e49d9fc363082719eeeaadf5c94560d253bd4455541e7c062fcdf4dd21081b4b529cb06ba257e03b95cbae5c6f44ff757f9da922fe3d0d09
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -20,7 +20,9 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
In Node class, `include TreeGraph`, then implement two methods, `label_for_tree_graph` and `children_for_tree_graph`(which return thing responds to `each`). Then you can call `tree_graph` and `
|
23
|
+
In Node class, `include TreeGraph`, then implement two methods, `label_for_tree_graph` and `children_for_tree_graph`(which return thing responds to `each`). Then you can call `tree_graph`, `tree_graph_bottom_up` and `tree_graph_bottom_up_in_same_order` on that Node object.
|
24
|
+
|
25
|
+
By default, `::Object#label_for_tree_graph` call `to_s`, and `::Object#children_for_tree_graph` return empty array.
|
24
26
|
|
25
27
|
Or checkout [test/tree_graph_test.rb](https://github.com/turnon/tree_graph/blob/master/test/tree_graph_test.rb) to see how to use.
|
26
28
|
|
data/lib/tree_graph/version.rb
CHANGED
data/lib/tree_graph.rb
CHANGED
@@ -10,6 +10,22 @@ module TreeGraph
|
|
10
10
|
BottomUp.new(self).tree_graph
|
11
11
|
end
|
12
12
|
|
13
|
+
def tree_graph_bottom_up_in_same_order
|
14
|
+
BottomUpInSameOrder.new(self).tree_graph
|
15
|
+
end
|
16
|
+
|
17
|
+
EMPTY_ARRAY = []
|
18
|
+
|
19
|
+
class ::Object
|
20
|
+
def label_for_tree_graph
|
21
|
+
to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def children_for_tree_graph
|
25
|
+
EMPTY_ARRAY
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
module Node
|
14
30
|
|
15
31
|
attr_accessor :is_last
|
@@ -20,13 +36,15 @@ module TreeGraph
|
|
20
36
|
end
|
21
37
|
|
22
38
|
def children_nodes
|
23
|
-
children
|
24
|
-
|
25
|
-
|
39
|
+
children.map do |c|
|
40
|
+
self.class.new(c, self)
|
41
|
+
end.tap do |nodes|
|
42
|
+
nodes.last.is_last = true unless nodes.empty?
|
26
43
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
def children
|
47
|
+
raw_node.children_for_tree_graph
|
30
48
|
end
|
31
49
|
|
32
50
|
def level
|
@@ -38,7 +56,7 @@ module TreeGraph
|
|
38
56
|
end
|
39
57
|
|
40
58
|
def ancestors
|
41
|
-
return
|
59
|
+
return EMPTY_ARRAY unless parent
|
42
60
|
parent.ancestors + [parent]
|
43
61
|
end
|
44
62
|
|
@@ -79,4 +97,10 @@ module TreeGraph
|
|
79
97
|
is_last ? '┌─' : '├─'
|
80
98
|
end
|
81
99
|
end
|
100
|
+
|
101
|
+
class BottomUpInSameOrder < BottomUp
|
102
|
+
def children
|
103
|
+
super.reverse
|
104
|
+
end
|
105
|
+
end
|
82
106
|
end
|
data/tree_graph.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "
|
24
|
-
spec.add_development_dependency "rake", "
|
23
|
+
spec.add_development_dependency "bundler", ">= 2.2.33"
|
24
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
25
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
26
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tree_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.33
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.6.8
|
92
|
+
rubygems_version: 3.1.6
|
94
93
|
signing_key:
|
95
94
|
specification_version: 4
|
96
95
|
summary: A mixin to help you generate tree graph
|