rexle 0.5.10 → 0.5.11

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 +17 -8
  2. metadata +1 -1
data/lib/rexle.rb CHANGED
@@ -49,7 +49,7 @@ class Rexle
49
49
  end
50
50
 
51
51
  class Element
52
- attr_accessor :name, :value
52
+ attr_accessor :name, :value, :parent
53
53
  attr_reader :child_lookup
54
54
 
55
55
  def initialize(name=nil, value='', attributes={})
@@ -140,20 +140,28 @@ class Rexle
140
140
  def add_element(item)
141
141
  @child_lookup << [item.name, item.attributes, item.value]
142
142
  @child_elements << item
143
+ # add a reference from this element (the parent) to the child
144
+ item.parent = self
143
145
  end
144
146
 
145
147
  alias add add_element
146
148
 
147
- def attributes() @attributes end
148
-
149
- def children() @child_elements end
150
-
149
+ def add_attribute(h={}) @attributes.merge h end
150
+ def attributes() @attributes end
151
+ def children() @child_elements end
151
152
  def children=(a) @child_elements = a end
152
153
 
153
- def element(s)
154
- self.xpath(s).first
154
+ def delete(obj=nil)
155
+ if obj then
156
+ i = @child_elements.index(obj)
157
+ [@child_elements, @child_lookup].each{|x| x.delete_at i} if i
158
+ else
159
+ self.parent.delete self
160
+ end
155
161
  end
156
162
 
163
+ def element(s) self.xpath(s).first end
164
+
157
165
  def text(s='')
158
166
  s.empty? ? @value : self.xpath(s).first.value
159
167
  end
@@ -288,6 +296,7 @@ class Rexle
288
296
  self
289
297
  end
290
298
 
299
+ def delete(xpath) @doc.element(xpath).delete end
291
300
  def element(xpath) @doc.element(xpath) end
292
301
  def text(xpath) @doc.text(xpath) end
293
302
  def root() @doc end
@@ -353,4 +362,4 @@ class Rexle
353
362
  [node.name, node.text.to_s, attributes, *children]
354
363
  end
355
364
 
356
- end
365
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.11
5
5
  platform: ruby
6
6
  authors: []
7
7