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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98ccffa0747e6642b106241a0aa1cf9fe9d9a406
4
- data.tar.gz: 72d58407cf20d8e0b73392a7a7171ede26429036
3
+ metadata.gz: 7e031ba9a1b346d19bccb1dada35c1221397fc70
4
+ data.tar.gz: e45c2c268c7bbfc2e7bc00ac646dc93d3ae2dc05
5
5
  SHA512:
6
- metadata.gz: 245281f5e9393ca8358799e6b41abda704bbe8af808be7e4787a561da8ca0673467c45a21d5b9dfc83de2964198c3b6acd2271750976a00a8b04ad013073f75a
7
- data.tar.gz: 91508434cd16cd1b9baa05ce183ade2f1e698f564e3a5233dcec784e279847ed64fcefebb6ffe4bed819caae3889cfcc59005321e0625479a9c9eed2f55c8abe
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
- build_for(root_word, nil)
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
- relationships.first.parent_word
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 = edges.map do |edge|
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.1
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-01-31 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec