rexle 0.1.0 → 0.1.1

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 +25 -7
  2. metadata +2 -2
data/lib/rexle.rb CHANGED
@@ -19,7 +19,7 @@ class Rexle
19
19
  @name, @value, @attributes = name, value, attributes
20
20
  raise "Element name must not be blank" unless name
21
21
  @child_elements = []
22
- @child_lookup = {}
22
+ @child_lookup = []
23
23
  end
24
24
 
25
25
  def children()
@@ -31,19 +31,37 @@ class Rexle
31
31
  end
32
32
 
33
33
  def add_element(item)
34
- @child_lookup[item.name] = item.value
34
+ @child_lookup << [item.name, item.attributes, item.value]
35
35
  @child_elements << item
36
- end
36
+ end
37
37
 
38
38
  def xpath(xpath_value)
39
39
 
40
40
  a = xpath_value.split('/')
41
- element_name = a.shift
41
+ s = a.shift
42
+
43
+ element_name, condition = s.split(/\[/)
44
+
45
+ if condition then
46
+ raw_items = condition.scan(/[\w]+=\'[^\']+\'|and/)
42
47
 
43
- index = @child_lookup.keys.index(element_name)
44
- if index then
48
+ items = raw_items.map do |x|
49
+ name, value = x.split(/=/)
50
+ [name, (value ? value[1..-2] : '')]
51
+ end
52
+ end
53
+
54
+ return_elements = @child_lookup.map.with_index.select {|x| x[0][0] == element_name}
55
+
56
+ count = return_elements.length
57
+ if count > 0 then
45
58
  if a.empty? then
46
- @child_elements[index]
59
+ if count == 1 then
60
+ index = return_elements[0][-1]
61
+ @child_elements[index]
62
+ else
63
+ return_elements.map{|x| @child_elements[x.last]}
64
+ end
47
65
  else
48
66
  @child_elements[index].xpath a.join
49
67
  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.1.0
4
+ version: 0.1.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-10-08 00:00:00 +01:00
12
+ date: 2010-10-16 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15