rexle 0.9.66 → 0.9.67

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rexle.rb +24 -1
  2. metadata +1 -1
data/lib/rexle.rb CHANGED
@@ -87,6 +87,25 @@ module XMLhelper
87
87
  end
88
88
 
89
89
  end
90
+
91
+ def scan_to_a(nodes)
92
+
93
+ nodes.inject([]) do |r,x|
94
+
95
+ if x.is_a? Rexle::Element then
96
+
97
+ a = [x.name, x.value, x.attributes]
98
+ (a.concat(scan_to_a(x.children[1..-1]))) if x.children.length > 1
99
+ r << a
100
+ elsif x.is_a? String then
101
+
102
+ r << x
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
90
109
 
91
110
  def pretty_print(nodes, indent='0')
92
111
  indent = indent.to_i
@@ -545,6 +564,10 @@ class Rexle
545
564
  end
546
565
 
547
566
  alias text= value=
567
+
568
+ def to_a()
569
+ [self.name, self.value, self.attributes, *scan_to_a(self.children)]
570
+ end
548
571
 
549
572
  def xml(options={})
550
573
  o = {pretty: false}.merge(options)
@@ -748,7 +771,7 @@ class Rexle
748
771
  raise 'attempted adding second root element to document' if @doc.root
749
772
  @doc.root.add_element(element)
750
773
  else
751
- doc_node = ['doc','',{},[element.name, element.value,element.attributes]]
774
+ doc_node = ['doc', '', {}, element.to_a]
752
775
  @doc = scan_element(*doc_node)
753
776
  end
754
777
  element
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.66
5
+ version: 0.9.67
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson