rogdl 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/node.rb +17 -1
- data/test/test_node.rb +22 -0
- metadata +1 -1
data/lib/node.rb
CHANGED
@@ -3,12 +3,28 @@ module Rogdl
|
|
3
3
|
include Enumerable
|
4
4
|
include Comparable
|
5
5
|
|
6
|
-
attr_accessor :gname
|
6
|
+
attr_accessor :gname
|
7
7
|
|
8
8
|
def initialize(aName)
|
9
9
|
self.gname = aName
|
10
10
|
end
|
11
11
|
|
12
|
+
def gparent(arg=1)
|
13
|
+
return @gparent if arg == 1
|
14
|
+
if arg.is_a?(Fixnum)
|
15
|
+
return self if arg == 0
|
16
|
+
return @gparent.gparent(arg-1)
|
17
|
+
end
|
18
|
+
if arg.is_a?(String)
|
19
|
+
return @gparent if @gparent.nil? || @gparent.gname == arg
|
20
|
+
return @gparent.gparent(arg)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def gparent=(aNode)
|
25
|
+
@gparent = aNode
|
26
|
+
end
|
27
|
+
|
12
28
|
def subs(key,value)
|
13
29
|
@@subs ||= {}
|
14
30
|
@@subs[key] = value
|
data/test/test_node.rb
CHANGED
@@ -235,6 +235,28 @@ class TestNode < Test::Unit::TestCase
|
|
235
235
|
|
236
236
|
end
|
237
237
|
|
238
|
+
def test_gparent_accessor
|
239
|
+
a = Node.new('a')
|
240
|
+
a.gparent = Node.new('b')
|
241
|
+
assert_equal 'b', a.gparent.gname
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_gparent
|
245
|
+
a = Node.new('a')
|
246
|
+
b = Node.new('b')
|
247
|
+
c = Node.new('c')
|
248
|
+
a.add(b)
|
249
|
+
b.add(c)
|
250
|
+
assert_equal 'a', c.gparent(2).gname
|
251
|
+
assert_equal 'b', c.gparent(1).gname
|
252
|
+
assert_equal 'c', c.gparent(0).gname
|
253
|
+
|
254
|
+
assert_equal 'a', c.gparent('a').gname
|
255
|
+
assert_equal 'b', c.gparent('b').gname
|
256
|
+
assert_equal nil, c.gparent('c')
|
257
|
+
|
258
|
+
end
|
259
|
+
|
238
260
|
|
239
261
|
|
240
262
|
|