rexle 0.6.0 → 0.6.1

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 -3
  2. metadata +2 -2
@@ -109,7 +109,7 @@ class Rexle
109
109
  rlist << return_elements.map.with_index do |x,i|
110
110
  rtn_element = filter(x, i+1, attr_search){|e| r = e.xpath(a_path.join('/'), &blk); (r || e) }
111
111
  next if rtn_element.nil? or (rtn_element.is_a? Array and rtn_element.empty?)
112
-
112
+ def add_attribute(h={}) @attributes.merge! h end
113
113
  if rtn_element.is_a? Array then
114
114
  rtn_element
115
115
  elsif (rtn_element.is_a? String) || (rtn_element.is_a?(Array) and not(rtn_element[0].is_a? String))
@@ -166,6 +166,15 @@ class Rexle
166
166
  end
167
167
 
168
168
  def element(s) self.xpath(s).first end
169
+
170
+ def elements(s=nil)
171
+ procs = {
172
+ NilClass: proc {Elements.new(@child_elements)},
173
+ String: proc {|x| @child_elements[x]}
174
+ }
175
+ procs[s.class.to_s.to_sym].call(s)
176
+ end
177
+
169
178
  def root() self end
170
179
  def text(s='')
171
180
  s.empty? ? @value : self.xpath(s).first.value
@@ -288,6 +297,17 @@ class Rexle
288
297
 
289
298
  end # -- end of element --
290
299
 
300
+ class Elements
301
+ def initialize(elements=[])
302
+ @elements = elements
303
+ end
304
+
305
+ def [](i)
306
+ @elements[i-1]
307
+ end
308
+ end
309
+
310
+
291
311
  def parse(x=nil)
292
312
 
293
313
  a = []
@@ -312,9 +332,10 @@ class Rexle
312
332
  alias add add_element
313
333
 
314
334
  def delete(xpath) @doc.element(xpath).delete end
315
- def element(xpath) @doc.element(xpath) end
316
- def text(xpath) @doc.text(xpath) end
335
+ def element(xpath) @doc.element(xpath) end
336
+ def elements(s=nil) @doc.elements(s) end
317
337
  def to_s() self.xml end
338
+ def text(xpath) @doc.text(xpath) end
318
339
  def root() @doc end
319
340
  def write() "<?xml version='1.0' encoding='UTF-8'?>\n" + xml end
320
341
  def xml()
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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-12-01 00:00:00 +00:00
12
+ date: 2010-12-02 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency