rexle 0.9.61 → 0.9.62

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.
Files changed (2) hide show
  1. data/lib/rexle.rb +21 -14
  2. metadata +2 -2
data/lib/rexle.rb CHANGED
@@ -10,6 +10,7 @@ require 'cgi'
10
10
  include REXML
11
11
 
12
12
  # modifications:
13
+ # 21-Oct-2012: xpath predicate now implemented e.g. fun/@id='4' => true
13
14
  # 20-Oct-2012: feature: added Rexle::Element#texts which is the equivalent
14
15
  # of REXML::Element#texts
15
16
  # feature: Rexle::Element#add_text is now the equivalent of
@@ -193,7 +194,7 @@ class Rexle
193
194
  end
194
195
 
195
196
  def max(path)
196
- a = query_xpath(path).flatten.compact.map(&:to_i)
197
+ a = query_xpath(path).flatten.select{|x| x.is_a? String}.map(&:to_i)
197
198
  a.max
198
199
  end
199
200
 
@@ -228,11 +229,11 @@ class Rexle
228
229
  }
229
230
  bucket = []
230
231
  raw_results = path.split('|').map do |xp|
231
- query_xpath(xp, bucket, &blk)
232
+ query_xpath(xp, bucket, &blk)
232
233
  end
233
-
234
- #results = raw_results.inject(&:+)
235
- results = raw_results.last
234
+
235
+ results = raw_results.last
236
+ results = [true] if results.is_a? Array and results.flatten.any?{|x| x == true}
236
237
  procs[results.class.to_s.to_sym].call(results) if results
237
238
 
238
239
  else
@@ -284,7 +285,7 @@ class Rexle
284
285
  else
285
286
 
286
287
  attribute = xpath_value[/^(attribute::|@)(.*)/,2]
287
-
288
+
288
289
  return @attributes if attribute == '*'
289
290
  return [@attributes[attribute.to_sym]] if attribute and @attributes and @attributes.has_key?(attribute.to_sym)
290
291
  s = a_path.shift
@@ -299,22 +300,30 @@ class Rexle
299
300
  unless element_part[/^@/] then
300
301
  element_name = element_part[/^[\w:\*\.]+/]
301
302
  else
303
+ if xpath_value[/^\[/] then
304
+ condition = xpath_value
305
+ element_name = nil
306
+ else
307
+ condition = element_part
308
+ attr_search = format_condition('[' + condition + ']')
309
+ return [attribute_search(attr_search, self, self.attributes) == nil]
310
+ end
302
311
 
303
- condition = xpath_value[/^\[/] ? xpath_value : element_part
304
- element_name = nil
305
312
  end
306
313
 
307
314
  end
308
315
 
309
316
  #element_name ||= '*'
310
317
  raw_condition = '' if condition
318
+
311
319
  attr_search = format_condition(condition) if condition and condition.length > 0
312
-
313
320
  attr_search2 = xpath_value[/^\[(.*)\]$/,1]
321
+
314
322
  if attr_search2 then
315
323
  r4 = attribute_search(attr_search, self, self.attributes)
316
324
  return r4
317
- end
325
+ end
326
+
318
327
 
319
328
  return_elements = []
320
329
 
@@ -426,9 +435,7 @@ class Rexle
426
435
  if @child_elements.length < 1 then
427
436
  @value = s;
428
437
  else
429
- if @child_elements.last.is_a? Rexle::Element then
430
- self.add s
431
- end
438
+ self.add s
432
439
  end
433
440
  self
434
441
  end
@@ -802,4 +809,4 @@ class Rexle
802
809
  [node.name, node.text.to_s, attributes, *children]
803
810
  end
804
811
 
805
- end
812
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.61
5
+ version: 0.9.62
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-10-21 00:00:00 Z
13
+ date: 2012-10-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rexleparser