ascii_tree 1.0.1 → 1.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/ascii_tree/node_builder.rb +10 -2
- data/lib/ascii_tree/relationships_builder.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e031ba9a1b346d19bccb1dada35c1221397fc70
|
4
|
+
data.tar.gz: e45c2c268c7bbfc2e7bc00ac646dc93d3ae2dc05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 128c1e4d53c452c820c0b966a7d02fb1362b36e8a7a0d34ca1dd9294fbd4318d7921ae566ddd3d2c340967c6214c3b210bec7fb5073517df5c2cb044fb9a51ae
|
7
|
+
data.tar.gz: ee4ba71fe8e4bbe8866bef686fb87ccd9dda2550e7220f7dde4c52bf678d14f39b909206e6aa27fe1bce51a92d75c161568317cf4330d19f9536866737030d33
|
@@ -10,7 +10,11 @@ module AsciiTree
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def build
|
13
|
-
|
13
|
+
if relationships.any?
|
14
|
+
build_for(root_word, nil)
|
15
|
+
else
|
16
|
+
nil
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
private
|
@@ -18,7 +22,11 @@ module AsciiTree
|
|
18
22
|
attr_reader :relationships
|
19
23
|
|
20
24
|
def root_word
|
21
|
-
|
25
|
+
root_relationship.child_word
|
26
|
+
end
|
27
|
+
|
28
|
+
def root_relationship
|
29
|
+
relationships.detect { |r| r.parent_word.nil? }
|
22
30
|
end
|
23
31
|
|
24
32
|
def build_for(word, parent)
|
@@ -3,7 +3,12 @@ module AsciiTree
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
def build(words, edges)
|
6
|
-
relationships =
|
6
|
+
relationships = []
|
7
|
+
|
8
|
+
root_relationship = root_relationship(words)
|
9
|
+
relationships << root_relationship if root_relationship
|
10
|
+
|
11
|
+
relationships += edges.map do |edge|
|
7
12
|
parent = words.detect { |w| w.include?(edge.parent_coordinate) }
|
8
13
|
child = words.detect { |w| w.include?(edge.child_coordinate) }
|
9
14
|
|
@@ -18,6 +23,14 @@ module AsciiTree
|
|
18
23
|
|
19
24
|
private
|
20
25
|
|
26
|
+
def root_relationship(words)
|
27
|
+
root_word = words.first
|
28
|
+
|
29
|
+
if root_word
|
30
|
+
Relationship.new(parent_word: nil, edge: nil, child_word: root_word)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
21
34
|
def validate_presence(parent, child, edge)
|
22
35
|
if parent.nil? && child.nil?
|
23
36
|
error = "No parent or child"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ascii_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Patuzzo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|