gf-treevisitor 0.0.11 → 0.0.12

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
data/lib/treevisitor.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class TreeVisitor
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -49,7 +49,7 @@ class AbsNode
49
49
  #
50
50
  def invalidate
51
51
  @path = nil
52
- @path_from_root = nil
52
+ @path_with_prefix = nil
53
53
  @depth = nil
54
54
  end
55
55
 
@@ -81,21 +81,21 @@ class AbsNode
81
81
  def path
82
82
  return @path unless @path.nil?
83
83
  if @parent.nil?
84
- @path = @prefix_path.nil? ? @name : @prefix_path + @name
84
+ @path = @name
85
85
  else
86
86
  @path = @parent.path + AbsNode::path_separator + @name
87
87
  end
88
88
  @path
89
89
  end
90
90
 
91
- def path_from_root
92
- return @path_from_root unless @path_from_root.nil?
91
+ def path_with_prefix
92
+ return @path_with_prefix unless @path_with_prefix.nil?
93
93
  if @parent.nil?
94
- @path_from_root = @prefix_path.nil? ? "" : @prefix_path
94
+ @path_with_prefix = @prefix_path.nil? ? @name : @prefix_path + @name
95
95
  else
96
- @path_from_root = @parent.path_from_root + AbsNode::path_separator + @name
96
+ @path_with_prefix = @parent.path_with_prefix + AbsNode::path_separator + @name
97
97
  end
98
- @path_from_root
98
+ @path_with_prefix
99
99
  end
100
100
 
101
101
  def depth
@@ -63,14 +63,16 @@ class TreeNode < AbsNode
63
63
  @leaves << leaf
64
64
  end
65
65
 
66
- def add_child( treeNode )
67
- return if treeNode.parent == self
68
- if not treeNode.parent.nil?
69
- treeNode.remove_from_parent()
66
+ def add_child( tree_node )
67
+ return if tree_node.parent == self
68
+ if not tree_node.parent.nil?
69
+ tree_node.remove_from_parent()
70
+ else
71
+ tree_node.prefix_path = nil
70
72
  end
71
- treeNode.invalidate
72
- treeNode.parent = self
73
- @children << treeNode
73
+ tree_node.invalidate
74
+ tree_node.parent = self
75
+ @children << tree_node
74
76
  end
75
77
 
76
78
  def find( name )
@@ -86,13 +86,18 @@ class TCTreeNode < Test::Unit::TestCase
86
86
  tb = TreeNode.new( "b", ta )
87
87
  ln3 = LeafNode.new( "3", tb )
88
88
 
89
- assert_equal( "a", ta.path )
89
+ assert_equal( "a", ta.path )
90
90
  assert_equal( "a/b", tb.path )
91
+ assert_equal( "a", ta.path_with_prefix )
92
+ assert_equal( "a/b", tb.path_with_prefix )
91
93
 
92
94
  ta.prefix_path= "<root>/"
93
-
94
- assert_equal( "<root>/a", ta.path )
95
- assert_equal( "<root>/a/b", tb.path )
95
+
96
+ assert_equal("<root>/", ta.prefix_path )
97
+ assert_equal( "a", ta.path )
98
+ assert_equal( "a/b", tb.path )
99
+ assert_equal( "<root>/a", ta.path_with_prefix )
100
+ assert_equal( "<root>/a/b", tb.path_with_prefix )
96
101
  end
97
102
 
98
103
  def test_invalidate
@@ -101,20 +106,20 @@ class TCTreeNode < Test::Unit::TestCase
101
106
  ln2 = LeafNode.new("2", ta)
102
107
  tb = TreeNode.new( "b", ta )
103
108
  ln3 = LeafNode.new( "3", tb )
104
-
105
- #@path = nil
106
- #@path_from_root = nil
107
- #@depth = nil
108
109
 
109
-
110
+ ta.prefix_path="root/"
110
111
  assert_equal( "a/b", tb.path )
111
- assert_equal( "/b", tb.path_from_root )
112
+ assert_equal( "root/a/b", tb.path_with_prefix )
112
113
  assert_equal( 2, tb.depth )
113
114
 
114
115
  r = TreeNode.new( "r" )
115
116
  r.add_child( ta )
116
117
  assert_equal( "r/a/b", tb.path )
117
- assert_equal( "/a/b", tb.path_from_root )
118
+ assert_equal( "r/a/b", tb.path_with_prefix )
119
+
120
+ r.prefix_path="new_root/"
121
+ assert_equal( "r/a/b", tb.path )
122
+ assert_equal( "new_root/r/a/b", tb.path_with_prefix )
118
123
  assert_equal( 3, tb.depth )
119
124
  end
120
125
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gf-treevisitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - gf