ixyml 0.0.1 → 0.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.
- data/Gemfile.lock +1 -1
- data/lib/ixyml/version.rb +1 -1
- data/lib/ixyml/xyml_element.rb +184 -10
- data/test/test_xyml_element.rb +53 -22
- metadata +2 -8
data/Gemfile.lock
CHANGED
data/lib/ixyml/version.rb
CHANGED
data/lib/ixyml/xyml_element.rb
CHANGED
|
@@ -90,6 +90,8 @@
|
|
|
90
90
|
# | d : delete | | sp: previous sibling | +---------------------------------+
|
|
91
91
|
# | s : set | | ss: immediately |
|
|
92
92
|
# +---------------+ | succeeding sibling |
|
|
93
|
+
# | d : descendants |
|
|
94
|
+
# | df: first descendant |
|
|
93
95
|
# | p : parent |
|
|
94
96
|
# | r : root |
|
|
95
97
|
# | a : attribute |
|
|
@@ -110,13 +112,15 @@
|
|
|
110
112
|
# # - b: ccc
|
|
111
113
|
# # - d:
|
|
112
114
|
# # - e: fff
|
|
115
|
+
# # - h:
|
|
116
|
+
# # -e: ggg
|
|
113
117
|
# # - d:
|
|
114
118
|
# # - e: ggg
|
|
115
119
|
# # - text
|
|
116
120
|
# # - h:
|
|
117
121
|
# # - e: fff
|
|
118
122
|
# xyml_tree=Xyml::Document.new(File.open("aaa.xyml"))
|
|
119
|
-
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]}]
|
|
123
|
+
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]}]
|
|
120
124
|
#
|
|
121
125
|
module Xyml_element
|
|
122
126
|
|
|
@@ -137,7 +141,7 @@ module Xyml_element
|
|
|
137
141
|
# エレメントの配列
|
|
138
142
|
#
|
|
139
143
|
# xyml_tree.root.gc
|
|
140
|
-
# #-> [{d:[{e:"fff"}]},{d:[{e:"ggg"}]},{h:[{e:'fff'}]}]
|
|
144
|
+
# #-> [{d:[{e:"fff"},{h:[{e:'ggg'}]}},{d:[{e:"ggg"}]},{h:[{e:'fff'}]}]
|
|
141
145
|
def gc
|
|
142
146
|
array=Array.new
|
|
143
147
|
self.values[0].each do |child|
|
|
@@ -155,7 +159,7 @@ module Xyml_element
|
|
|
155
159
|
# エレメント(子エレメントが無い場合は'nil')
|
|
156
160
|
#
|
|
157
161
|
# xyml_tree.root.gcf
|
|
158
|
-
# #-> {d:[{e:'fff'}]}
|
|
162
|
+
# #-> {d:[{e:'fff'},{h:[{e:'ggg'}]}]}
|
|
159
163
|
def gcf
|
|
160
164
|
self.values[0].each do |child|
|
|
161
165
|
return child if child.is_a?(Hash) && child.values[0].is_a?(Array)
|
|
@@ -176,7 +180,7 @@ module Xyml_element
|
|
|
176
180
|
# エレメントの配列
|
|
177
181
|
#
|
|
178
182
|
# xyml_tree.root.gcn 'd' # or xyml_tree.root.gcn :d
|
|
179
|
-
# #-> [{d:[{e:"fff"}]},{d:[{e:"ggg"},'text']}]
|
|
183
|
+
# #-> [{d:[{e:"fff"},{h:[{e:'ggg'}]}]},{d:[{e:"ggg"},'text']}]
|
|
180
184
|
def gcn ename
|
|
181
185
|
ename=ename.intern if ename.is_a?(String)
|
|
182
186
|
array=Array.new
|
|
@@ -186,6 +190,28 @@ module Xyml_element
|
|
|
186
190
|
array
|
|
187
191
|
end
|
|
188
192
|
|
|
193
|
+
# get descendant elements with the designated name.
|
|
194
|
+
#
|
|
195
|
+
# 指定された名前を持つ子孫エレメントの取得
|
|
196
|
+
# ==== Args
|
|
197
|
+
# _ename_ :: element name(string or symbol).
|
|
198
|
+
#
|
|
199
|
+
# _ename_ :: エレメント名(文字列もしくはシンボル)
|
|
200
|
+
# ==== Return
|
|
201
|
+
# an array of elements.
|
|
202
|
+
#
|
|
203
|
+
# エレメントの配列
|
|
204
|
+
#
|
|
205
|
+
# xyml_tree.root.gdn 'h' # or xyml_tree.root.gdn :h
|
|
206
|
+
# #-> [{h:[{e:"ggg"}]},{h:[{e:"fff"},'text']}]
|
|
207
|
+
def gdn ename
|
|
208
|
+
ename=ename.intern if ename.is_a?(String)
|
|
209
|
+
array=Array.new
|
|
210
|
+
gdn_rcsv self,array,ename
|
|
211
|
+
array
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
|
|
189
215
|
# get the first child element with the designated name.
|
|
190
216
|
#
|
|
191
217
|
# 指定された名前を持つ最初の子エレメントの取得
|
|
@@ -204,6 +230,21 @@ module Xyml_element
|
|
|
204
230
|
nil
|
|
205
231
|
end
|
|
206
232
|
|
|
233
|
+
# get the first(depth-first search) descendant element with the designated name.
|
|
234
|
+
#
|
|
235
|
+
# 指定された名前を持つ(深さ優先探索での)最初の子孫エレメントの取得
|
|
236
|
+
# ==== Return
|
|
237
|
+
# an element, or nil if no descendant element with the designated name.
|
|
238
|
+
#
|
|
239
|
+
# エレメント(指定された名前の子孫エレメントが無い場合は'nil')
|
|
240
|
+
#
|
|
241
|
+
# xyml_tree.root.gdfn 'h' # or xyml_tree.root.gcfn :h
|
|
242
|
+
# #-> {h:[{e:"ggg"}]}
|
|
243
|
+
def gdfn ename
|
|
244
|
+
ename=ename.intern if ename.is_a?(String)
|
|
245
|
+
return gdfn_rcsv self,ename
|
|
246
|
+
end
|
|
247
|
+
|
|
207
248
|
# get child elements with the designated element name and atrribute.
|
|
208
249
|
#
|
|
209
250
|
# 指定された名前と属性を持つ子エレメントの取得
|
|
@@ -232,6 +273,32 @@ module Xyml_element
|
|
|
232
273
|
array
|
|
233
274
|
end
|
|
234
275
|
|
|
276
|
+
# get descendant elements with the designated element name and atrribute.
|
|
277
|
+
#
|
|
278
|
+
# 指定された名前と属性を持つ子孫エレメントの取得
|
|
279
|
+
# ==== Args
|
|
280
|
+
# _ename_ :: element name(string or symbol)
|
|
281
|
+
# _aname_ :: attribute name(string or symbol)
|
|
282
|
+
# _avalue_ :: attribute value
|
|
283
|
+
#
|
|
284
|
+
# _ename_ :: エレメント名(文字列もしくはシンボル)
|
|
285
|
+
# _aname_ :: 属性名(文字列もしくはシンボル)
|
|
286
|
+
# _avalue_ :: 属性値
|
|
287
|
+
# ==== Return
|
|
288
|
+
# an array of elements.
|
|
289
|
+
#
|
|
290
|
+
# エレメントの配列
|
|
291
|
+
#
|
|
292
|
+
# xyml_tree.root.gcna 'h','e','ggg'
|
|
293
|
+
# #-> [{h:[{e:"ggg"}]}]
|
|
294
|
+
def gdna ename,aname,avalue
|
|
295
|
+
ename=ename.intern if ename.is_a?(String)
|
|
296
|
+
aname=aname.intern if aname.is_a?(String)
|
|
297
|
+
array=Array.new
|
|
298
|
+
gdna_rcsv self,array,ename,aname,avalue
|
|
299
|
+
array
|
|
300
|
+
end
|
|
301
|
+
|
|
235
302
|
# get child elements with the designated atrribute.
|
|
236
303
|
#
|
|
237
304
|
# 指定された属性を持つ子エレメントの取得
|
|
@@ -257,6 +324,28 @@ module Xyml_element
|
|
|
257
324
|
array
|
|
258
325
|
end
|
|
259
326
|
|
|
327
|
+
# get descendant elements with the designated atrribute.
|
|
328
|
+
#
|
|
329
|
+
# 指定された属性を持つ子孫エレメントの取得
|
|
330
|
+
# ==== Args
|
|
331
|
+
# _aname_ :: attribute name(string or symbol)
|
|
332
|
+
# _avalue_ :: attribute value
|
|
333
|
+
#
|
|
334
|
+
# _aname_ :: 属性名(文字列もしくはシンボル)
|
|
335
|
+
# _avalue_ :: 属性値
|
|
336
|
+
# ==== Return
|
|
337
|
+
# an array of elements.
|
|
338
|
+
#
|
|
339
|
+
# エレメントの配列
|
|
340
|
+
#
|
|
341
|
+
# xyml_tree.root.gca 'e','ggg'
|
|
342
|
+
# #-> [{h:[{e:"ggg"}]},{d:[{e:"ggg"}]}]
|
|
343
|
+
def gda aname,avalue
|
|
344
|
+
aname=aname.intern if aname.is_a?(String)
|
|
345
|
+
array=Array.new
|
|
346
|
+
gda_rcsv self,array,aname,avalue
|
|
347
|
+
array
|
|
348
|
+
end
|
|
260
349
|
|
|
261
350
|
# get the first child elements with the designated element name and atrribute.
|
|
262
351
|
#
|
|
@@ -285,6 +374,30 @@ module Xyml_element
|
|
|
285
374
|
nil
|
|
286
375
|
end
|
|
287
376
|
|
|
377
|
+
# get the first(depth-first search) descendant elements with the designated element name and atrribute.
|
|
378
|
+
#
|
|
379
|
+
# 指定された名前と属性を持つ最初の子孫エレメントの取得
|
|
380
|
+
# ==== Args
|
|
381
|
+
# _ename_ :: element name(string or symbol)
|
|
382
|
+
# _aname_ :: attribute name(string or symbol)
|
|
383
|
+
# _avalue_ :: attribute value
|
|
384
|
+
#
|
|
385
|
+
# _ename_ :: エレメント名(文字列もしくはシンボル)
|
|
386
|
+
# _aname_ :: 属性名(文字列もしくはシンボル)
|
|
387
|
+
# _avalue_ :: 属性値
|
|
388
|
+
# ==== Return
|
|
389
|
+
# an element, or nil if no descendant with the designated name and attribute.
|
|
390
|
+
#
|
|
391
|
+
# エレメント(指定された名前と属性の子孫エレメントが無い場合は'nil')
|
|
392
|
+
#
|
|
393
|
+
# xyml_tree.root.gcfna 'h','e','ggg'
|
|
394
|
+
# #-> {h:[{e:"ggg"}]}
|
|
395
|
+
def gdfna ename,aname,avalue
|
|
396
|
+
ename=ename.intern if ename.is_a?(String)
|
|
397
|
+
aname=aname.intern if aname.is_a?(String)
|
|
398
|
+
return gdfna_rcsv self,ename,aname,avalue
|
|
399
|
+
end
|
|
400
|
+
|
|
288
401
|
# get the previous sibling element.
|
|
289
402
|
#
|
|
290
403
|
# 直前のシブリング(兄弟姉妹)エレメントの取得。
|
|
@@ -296,7 +409,7 @@ module Xyml_element
|
|
|
296
409
|
# my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
297
410
|
# #-> {d:[{e:"ggg"},'text']}
|
|
298
411
|
# my_element.gsp
|
|
299
|
-
# #-> {d:[{e:"fff"}]}
|
|
412
|
+
# #-> {d:[{e:"fff"},{h:[{e:'ggg'}]}]}
|
|
300
413
|
def gsp
|
|
301
414
|
if parent=self.gp then
|
|
302
415
|
siblings=parent.gc
|
|
@@ -364,10 +477,10 @@ module Xyml_element
|
|
|
364
477
|
# my_element.gcf
|
|
365
478
|
# #-> {j:[{e:"kkk"}]}
|
|
366
479
|
# xyml_tree
|
|
367
|
-
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text',{j:[e:"kkk"]}]},{h:[{e:'fff'}]}]}] #<- element was added next to text.
|
|
480
|
+
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text',{j:[e:"kkk"]}]},{h:[{e:'fff'}]}]}] #<- element was added next to text.
|
|
368
481
|
# my_element.st(my_elment.gt) #<- text was unset and set again.
|
|
369
482
|
# xyml_tree
|
|
370
|
-
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},{j:[e:"kkk"]},'text']},{h:[{e:'fff'}]}]}] #<- text next to added element.
|
|
483
|
+
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},{j:[e:"kkk"]},'text']},{h:[{e:'fff'}]}]}] #<- text next to added element.
|
|
371
484
|
def ac elm
|
|
372
485
|
return nil unless elm.is_a?(Hash) and elm.values[0].is_a?(Array)
|
|
373
486
|
elm.extend Xyml_element
|
|
@@ -398,7 +511,7 @@ module Xyml_element
|
|
|
398
511
|
# my_element.gsp
|
|
399
512
|
# #-> {j:[{e:"kkk"}]}
|
|
400
513
|
# xyml_tree
|
|
401
|
-
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'}]},{j:[{e:"kkk"}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]}]
|
|
514
|
+
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{j:[{e:"kkk"}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]}]
|
|
402
515
|
def isp elm
|
|
403
516
|
return nil if self.gp==:_iamroot
|
|
404
517
|
elm.extend Xyml_element
|
|
@@ -435,7 +548,7 @@ module Xyml_element
|
|
|
435
548
|
# my_element.gss
|
|
436
549
|
# #-> {j:[{e:"kkk"}]}
|
|
437
550
|
# xyml_tree
|
|
438
|
-
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{j:[{e:"kkk"}]},{h:[{e:'fff'}]}]}]
|
|
551
|
+
# #-> [{a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{j:[{e:"kkk"}]},{h:[{e:'fff'}]}]}]
|
|
439
552
|
def iss elm
|
|
440
553
|
return nil if self.gp==:_iamroot
|
|
441
554
|
elm.extend Xyml_element
|
|
@@ -672,7 +785,7 @@ module Xyml_element
|
|
|
672
785
|
|
|
673
786
|
# delete the parent element information.
|
|
674
787
|
#
|
|
675
|
-
#
|
|
788
|
+
# 親エレメント情報の削除
|
|
676
789
|
# ==== Note
|
|
677
790
|
# this method is for the Xyml and Xyml_element package development use, not for users.
|
|
678
791
|
#
|
|
@@ -774,5 +887,66 @@ module Xyml_element
|
|
|
774
887
|
end
|
|
775
888
|
=end
|
|
776
889
|
|
|
890
|
+
private
|
|
891
|
+
|
|
892
|
+
def gdn_rcsv elm,array,ename
|
|
893
|
+
elm.values[0].each do |child|
|
|
894
|
+
if child.is_a?(Hash) && child.values[0].is_a?(Array) then
|
|
895
|
+
if child.keys[0]==ename then
|
|
896
|
+
array << child
|
|
897
|
+
end
|
|
898
|
+
gdn_rcsv child,array,ename
|
|
899
|
+
end
|
|
900
|
+
end
|
|
901
|
+
end
|
|
777
902
|
|
|
903
|
+
def gdfn_rcsv elm,ename
|
|
904
|
+
elm.values[0].each do |child|
|
|
905
|
+
if child.is_a?(Hash) && child.values[0].is_a?(Array) then
|
|
906
|
+
if child.keys[0]==ename then
|
|
907
|
+
return child;
|
|
908
|
+
end
|
|
909
|
+
if temp=gdfn_rcsv(child,ename) then
|
|
910
|
+
return temp
|
|
911
|
+
end
|
|
912
|
+
end
|
|
913
|
+
end
|
|
914
|
+
nil
|
|
915
|
+
end
|
|
916
|
+
|
|
917
|
+
def gdna_rcsv elm,array,ename,aname,avalue
|
|
918
|
+
elm.values[0].each do |child|
|
|
919
|
+
if child.is_a?(Hash) && child.values[0].is_a?(Array) then
|
|
920
|
+
if child.keys[0]==ename && child.ga(aname)==avalue then
|
|
921
|
+
array << child
|
|
922
|
+
end
|
|
923
|
+
gdna_rcsv child,array,ename,aname,avalue
|
|
924
|
+
end
|
|
925
|
+
end
|
|
926
|
+
end
|
|
927
|
+
|
|
928
|
+
def gda_rcsv elm,array,aname,avalue
|
|
929
|
+
elm.values[0].each do |child|
|
|
930
|
+
if child.is_a?(Hash) && child.values[0].is_a?(Array) then
|
|
931
|
+
if child.ga(aname)==avalue then
|
|
932
|
+
array << child
|
|
933
|
+
end
|
|
934
|
+
gda_rcsv child,array,aname,avalue
|
|
935
|
+
end
|
|
936
|
+
end
|
|
937
|
+
end
|
|
938
|
+
|
|
939
|
+
def gdfna_rcsv elm,ename,aname,avalue
|
|
940
|
+
elm.values[0].each do |child|
|
|
941
|
+
if child.is_a?(Hash) && child.values[0].is_a?(Array) then
|
|
942
|
+
if child.keys[0]==ename && child.ga(aname)==avalue then
|
|
943
|
+
return child
|
|
944
|
+
end
|
|
945
|
+
if temp=gdfna_rcsv(child,ename,aname,avalue) then
|
|
946
|
+
return temp
|
|
947
|
+
end
|
|
948
|
+
end
|
|
949
|
+
end
|
|
950
|
+
nil
|
|
951
|
+
end
|
|
778
952
|
end
|
data/test/test_xyml_element.rb
CHANGED
|
@@ -113,7 +113,7 @@ class TestDocument < Test::Unit::TestCase
|
|
|
113
113
|
|
|
114
114
|
should ". program samples in the document work correctly." do
|
|
115
115
|
# gc(get children)
|
|
116
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
116
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
117
117
|
assert_equal(:d,xyml_tree.root.gc[0].name)
|
|
118
118
|
assert_equal('fff',xyml_tree.root.gc[0].ga(:e))
|
|
119
119
|
assert_equal(:d,xyml_tree.root.gc[1].name)
|
|
@@ -121,48 +121,79 @@ class TestDocument < Test::Unit::TestCase
|
|
|
121
121
|
assert_equal(:h,xyml_tree.root.gc[2].name)
|
|
122
122
|
assert_equal('fff',xyml_tree.root.gc[2].ga(:e))
|
|
123
123
|
# gcf(get first child)
|
|
124
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
124
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
125
125
|
assert_equal(:d,xyml_tree.root.gcf.name)
|
|
126
126
|
assert_equal('fff',xyml_tree.root.gcf.ga(:e))
|
|
127
127
|
# gcn(get child elements with the designated name)
|
|
128
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
128
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
129
129
|
assert_equal(:d,xyml_tree.root.gcn(:d)[0].name)
|
|
130
130
|
assert_equal('fff',xyml_tree.root.gcn(:d)[0].ga(:e))
|
|
131
131
|
assert_equal(:d,xyml_tree.root.gcn(:d)[1].name)
|
|
132
132
|
assert_equal('ggg',xyml_tree.root.gcn(:d)[1].ga(:e))
|
|
133
133
|
assert_equal(2,xyml_tree.root.gcn(:d).size)
|
|
134
|
+
# gdn(get descendant elements with the designated name)
|
|
135
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
136
|
+
assert_equal(:h,xyml_tree.root.gdn(:h)[0].name)
|
|
137
|
+
assert_equal('ggg',xyml_tree.root.gdn(:h)[0].ga(:e))
|
|
138
|
+
assert_equal(:h,xyml_tree.root.gdn(:h)[1].name)
|
|
139
|
+
assert_equal('fff',xyml_tree.root.gdn(:h)[1].ga(:e))
|
|
140
|
+
assert_equal(2,xyml_tree.root.gdn(:h).size)
|
|
134
141
|
# gcfn(get the first child element with the designated name)
|
|
135
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
142
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
136
143
|
assert_equal(:d,xyml_tree.root.gcfn(:d).name)
|
|
137
144
|
assert_equal('fff',xyml_tree.root.gcfn(:d).ga(:e))
|
|
145
|
+
# gdfn(get the first descendant element with the designated name)
|
|
146
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
147
|
+
assert_equal(:h,xyml_tree.root.gdfn(:h).name)
|
|
148
|
+
assert_equal('ggg',xyml_tree.root.gdfn(:h).ga(:e))
|
|
149
|
+
assert_equal(nil,xyml_tree.root.gdfn(:k))
|
|
138
150
|
# gcna(get child elements with the designated element name and atrribute)
|
|
139
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
151
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
140
152
|
assert_equal(:d,xyml_tree.root.gcna(:d,:e,'ggg')[0].name)
|
|
141
153
|
assert_equal('ggg',xyml_tree.root.gcna(:d,:e,'ggg')[0].ga(:e))
|
|
142
154
|
assert_equal(1,xyml_tree.root.gcna(:d,:e,'fff').size)
|
|
155
|
+
# gdna(get descendant elements with the designated element name and atrribute)
|
|
156
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
157
|
+
assert_equal(:h,xyml_tree.root.gdna(:h,:e,'ggg')[0].name)
|
|
158
|
+
assert_equal('ggg',xyml_tree.root.gdna(:h,:e,'ggg')[0].ga(:e))
|
|
159
|
+
assert_equal(1,xyml_tree.root.gdna(:d,:e,'ggg').size)
|
|
160
|
+
assert_equal(0,xyml_tree.root.gdna(:d,:e,'abc').size)
|
|
143
161
|
# gca(get child elements with the designated atrribute)
|
|
144
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
162
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
145
163
|
assert_equal(:d,xyml_tree.root.gca(:e,'fff')[0].name)
|
|
146
164
|
assert_equal('fff',xyml_tree.root.gca(:e,'fff')[0].ga(:e))
|
|
147
165
|
assert_equal(:h,xyml_tree.root.gca(:e,'fff')[1].name)
|
|
148
166
|
assert_equal('fff',xyml_tree.root.gca(:e,'fff')[1].ga(:e))
|
|
149
167
|
assert_equal(2,xyml_tree.root.gca(:e,'fff').size)
|
|
168
|
+
# gda(get descendant elements with the designated atrribute)
|
|
169
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
170
|
+
assert_equal(:h,xyml_tree.root.gda(:e,'ggg')[0].name)
|
|
171
|
+
assert_equal('ggg',xyml_tree.root.gda(:e,'ggg')[0].ga(:e))
|
|
172
|
+
assert_equal(:d,xyml_tree.root.gda(:e,'ggg')[1].name)
|
|
173
|
+
assert_equal('ggg',xyml_tree.root.gda(:e,'ggg')[1].ga(:e))
|
|
174
|
+
assert_equal(2,xyml_tree.root.gda(:e,'ggg').size)
|
|
175
|
+
assert_equal(0,xyml_tree.root.gda(:e,'abc').size)
|
|
150
176
|
# gcfna(get the first child elements with the designated element name and atrribute)
|
|
151
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
177
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
152
178
|
assert_equal(:d,xyml_tree.root.gcfna(:d,:e,'ggg').name)
|
|
153
179
|
assert_equal('ggg',xyml_tree.root.gcfna(:d,:e,'ggg').ga(:e))
|
|
180
|
+
# gdfna(get the first descendant elements with the designated element name and atrribute)
|
|
181
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
182
|
+
assert_equal(:h,xyml_tree.root.gdfna(:h,:e,'ggg').name)
|
|
183
|
+
assert_equal('ggg',xyml_tree.root.gdfna(:h,:e,'ggg').ga(:e))
|
|
184
|
+
assert_equal(nil,xyml_tree.root.gdfna(:d,:e,'abc'))
|
|
154
185
|
# gsp(get the previous sibling element)
|
|
155
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
186
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
156
187
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
157
188
|
assert_equal(:d,my_element.gsp.name)
|
|
158
189
|
assert_equal('fff',my_element.gsp.ga(:e))
|
|
159
190
|
# gss(get the immediately succeeding sibling element)
|
|
160
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
191
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
161
192
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
162
193
|
assert_equal(:h,my_element.gss.name)
|
|
163
194
|
assert_equal('fff',my_element.gss.ga(:e))
|
|
164
195
|
# ac(add a child)
|
|
165
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
196
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
166
197
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
167
198
|
my_element.ac({j:[{e:'kkk'}]})
|
|
168
199
|
assert_equal(:j,my_element.gcf.name)
|
|
@@ -170,39 +201,39 @@ class TestDocument < Test::Unit::TestCase
|
|
|
170
201
|
my_element.st(my_element.gt)
|
|
171
202
|
assert_equal('text',my_element[:d][2])
|
|
172
203
|
# isp(insert an element as a previous sibling element)
|
|
173
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
204
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
174
205
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
175
206
|
my_element.isp({j:[{e:'kkk'}]})
|
|
176
207
|
assert_equal(:j,my_element.gsp.name)
|
|
177
208
|
assert_equal('kkk',my_element.gsp.ga(:e))
|
|
178
209
|
# iss(insert an element as an immediately succeeding sibling element)
|
|
179
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
210
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
180
211
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
181
212
|
my_element.iss({j:[{e:'kkk'}]})
|
|
182
213
|
assert_equal(:j,my_element.gss.name)
|
|
183
214
|
assert_equal('kkk',my_element.gss.ga(:e))
|
|
184
215
|
# ga(get value of attribute with the designated attribute name)
|
|
185
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
216
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
186
217
|
assert_equal('ccc',xyml_tree.root.ga(:b))
|
|
187
218
|
# sa(set value to the attribute with the designated attribute name)
|
|
188
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
219
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
189
220
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
190
221
|
my_element.sa(:e,'lll').sa(:m,'nnn')
|
|
191
222
|
assert_equal('lll',my_element.ga(:e))
|
|
192
223
|
assert_equal('nnn',my_element.ga(:m))
|
|
193
224
|
# da(delete attribute)
|
|
194
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
225
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
195
226
|
xyml_tree.root.da(:b)
|
|
196
227
|
assert_equal(nil,xyml_tree.root.ga(:b))
|
|
197
228
|
# gt(get text)
|
|
198
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
229
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
199
230
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
200
231
|
assert_equal('text',my_element.gt)
|
|
201
232
|
my_element.at 'abc'
|
|
202
233
|
assert_equal('textabc',my_element.gt)
|
|
203
234
|
assert_equal(['text','abc'],my_element.gt(:raw))
|
|
204
235
|
# st(set text)
|
|
205
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
236
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
206
237
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
207
238
|
my_element.st('abc')
|
|
208
239
|
assert_equal('abc',my_element.gt)
|
|
@@ -210,26 +241,26 @@ class TestDocument < Test::Unit::TestCase
|
|
|
210
241
|
assert_equal('',my_element.gt)
|
|
211
242
|
|
|
212
243
|
# at(add text)
|
|
213
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
244
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
214
245
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
215
246
|
my_element.at('abc')
|
|
216
247
|
assert_equal('textabc',my_element.gt)
|
|
217
248
|
# gp(get the parent element)
|
|
218
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
249
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
219
250
|
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
220
251
|
assert_equal(:a,my_element.gp.name)
|
|
221
252
|
assert_equal(nil,xyml_tree.root.gp)
|
|
222
253
|
# gr(get the root element)
|
|
223
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
254
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
224
255
|
new_element=Xyml::Element.new(:j)
|
|
225
256
|
xyml_tree.root.gcfna('d','e','ggg').ac new_element
|
|
226
257
|
assert_equal(:a,new_element.gr.name)
|
|
227
258
|
# is_root?
|
|
228
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
259
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
229
260
|
assert_equal(true,xyml_tree.root.is_root?)
|
|
230
261
|
assert_equal(false,xyml_tree.root.gcfna('d','e','ggg').is_root?)
|
|
231
262
|
# dsl(delete the self element from the child element array of its parent element)
|
|
232
|
-
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
263
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'},{h:[{e:'ggg'}]}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
233
264
|
xyml_tree.root.gcfna('d','e','ggg').dsl
|
|
234
265
|
assert_equal(:d,xyml_tree.root.gc[0].name)
|
|
235
266
|
assert_equal('fff',xyml_tree.root.gc[0].ga(:e))
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ixyml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: ! "I propose a new file format called \"XYML.\" Xyml module has the
|
|
15
15
|
following functions:\n * loads a XYML file as an instance of Xyml::Document, saves
|
|
@@ -133,18 +133,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
133
133
|
- - ! '>='
|
|
134
134
|
- !ruby/object:Gem::Version
|
|
135
135
|
version: '0'
|
|
136
|
-
segments:
|
|
137
|
-
- 0
|
|
138
|
-
hash: -351511487
|
|
139
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
137
|
none: false
|
|
141
138
|
requirements:
|
|
142
139
|
- - ! '>='
|
|
143
140
|
- !ruby/object:Gem::Version
|
|
144
141
|
version: '0'
|
|
145
|
-
segments:
|
|
146
|
-
- 0
|
|
147
|
-
hash: -351511487
|
|
148
142
|
requirements: []
|
|
149
143
|
rubyforge_project:
|
|
150
144
|
rubygems_version: 1.8.23
|