nutmeg 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nutmeg/tag_tree.rb +12 -1
- data/lib/nutmeg/version.rb +1 -1
- data/spec/tag_tree_spec.rb +13 -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: 0e145e3d4136c3bd7cc1d23db79957c83b23b0f5
|
4
|
+
data.tar.gz: e3ad9a629fa986c8ba291a014e236bb90559863d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a9a4d28872b0857bc802df4ec58b2567bd5d86ff12a5c4d00bdf6b3984e90cec98d05383bfe129a4006a9bcf6d1956be57da3b528d4ea2b8ac1082668227fa0
|
7
|
+
data.tar.gz: 0ffefd4c51cb0b276428b3506e58f579b47875cdc3db8f9396201ae1d49abd9d35175c61d20c86063b55fdbcda806ac9ebcf197eb044ce55000897c725ced285
|
data/lib/nutmeg/tag_tree.rb
CHANGED
@@ -34,10 +34,21 @@ module Nutmeg
|
|
34
34
|
@original.children.select{|l| tags_given.include?(l.content[:slug])}.collect{|leaf| ([leaf] + leaf.parentage).reverse }
|
35
35
|
end
|
36
36
|
|
37
|
+
def get_path_to_node(tag_slug, path_so_far = [])
|
38
|
+
node = @original.select{|node|node.content[:slug] == tag_slug}.first
|
39
|
+
return get_recursive_path_to_node(node, [node])
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_recursive_path_to_node(node, path_so_far)
|
43
|
+
return path_so_far if node.parent.nil?
|
44
|
+
path_so_far << node.parent
|
45
|
+
get_recursive_path_to_node(node.parent, path_so_far)
|
46
|
+
end
|
47
|
+
|
37
48
|
def get_paths_formatted(tags_given, seperator = "/")
|
38
49
|
get_paths(tags_given).collect do |tags|
|
39
50
|
tags.reject{|tag| tag.content[:slug] == "root"}.map{|node| node.content[:slug]}.join(seperator)
|
40
51
|
end
|
41
52
|
end
|
42
53
|
end
|
43
|
-
end
|
54
|
+
end
|
data/lib/nutmeg/version.rb
CHANGED
data/spec/tag_tree_spec.rb
CHANGED
@@ -43,4 +43,16 @@ describe Nutmeg::TagTree do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
|
+
describe "descendant nodes" do
|
48
|
+
it "Retrieve a path to a descendant node, given a leaf node" do
|
49
|
+
path = @tag_tree.get_path_to_node("child")
|
50
|
+
expect(path.length).to eql(3)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "Retrieve a path to a descendant node, given a middle-tree node" do
|
54
|
+
path = @tag_tree.get_path_to_node("base")
|
55
|
+
expect(path.length).to eql(2)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nutmeg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis van der Vliet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubytree
|