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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3bc6168f802956fc9192351902d875504a17cb1
4
- data.tar.gz: 8e38cb668205693fffe6d777447e023caa031d21
3
+ metadata.gz: 0e145e3d4136c3bd7cc1d23db79957c83b23b0f5
4
+ data.tar.gz: e3ad9a629fa986c8ba291a014e236bb90559863d
5
5
  SHA512:
6
- metadata.gz: 01282448b51d57ef6374c748e01b452dc7f709d9adacc7f0f4ebb5d330e71f06103532cc07d6dc06f5dd3d1bda1a60c14f96ffa19b2a2331ac25308a1a88be65
7
- data.tar.gz: 532d8e13b5fb4998bf8ea5c55661c08c56b26dcbd3cf513ba6f46bb3880d0c8e2c10e952effabfac5af04383a6dd8c68b18ac73eed18dcd34a404007cdac0fd7
6
+ metadata.gz: 3a9a4d28872b0857bc802df4ec58b2567bd5d86ff12a5c4d00bdf6b3984e90cec98d05383bfe129a4006a9bcf6d1956be57da3b528d4ea2b8ac1082668227fa0
7
+ data.tar.gz: 0ffefd4c51cb0b276428b3506e58f579b47875cdc3db8f9396201ae1d49abd9d35175c61d20c86063b55fdbcda806ac9ebcf197eb044ce55000897c725ced285
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Nutmeg
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
@@ -43,4 +43,16 @@ describe Nutmeg::TagTree do
43
43
  end
44
44
  end
45
45
  end
46
- end
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.13
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-02-17 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubytree