rexle 0.2.3 → 0.2.4
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.
- data/lib/rexle.rb +29 -8
- metadata +2 -2
data/lib/rexle.rb
CHANGED
@@ -14,11 +14,14 @@ class Rexle
|
|
14
14
|
|
15
15
|
if fn_match.nil? then
|
16
16
|
procs = {
|
17
|
-
Array: proc {|x|
|
17
|
+
Array: proc {|x| x.length == 1 ? x[0] : x},
|
18
18
|
String: proc {|x| x}
|
19
19
|
}
|
20
|
-
|
20
|
+
bucket = []
|
21
|
+
result = @doc.xpath(path, bucket)
|
22
|
+
|
21
23
|
procs[result.class.to_s.to_sym].call(result)
|
24
|
+
bucket
|
22
25
|
else
|
23
26
|
m, xpath_value = fn_match.captures
|
24
27
|
method(m.to_sym).call(xpath_value)
|
@@ -49,7 +52,7 @@ class Rexle
|
|
49
52
|
@child_elements << item
|
50
53
|
end
|
51
54
|
|
52
|
-
def xpath(xpath_value)
|
55
|
+
def xpath(xpath_value, rlist=[])
|
53
56
|
|
54
57
|
a = xpath_value.split('/')
|
55
58
|
|
@@ -86,24 +89,42 @@ class Rexle
|
|
86
89
|
|
87
90
|
end
|
88
91
|
|
89
|
-
wildcard =
|
92
|
+
wildcard = xpath_value[0,2] == '//'
|
93
|
+
|
94
|
+
if wildcard then
|
95
|
+
return scan_match(self, element_name, rlist)
|
96
|
+
end
|
97
|
+
|
90
98
|
return_elements = @child_lookup.map.with_index.select {|x| x[0][0] == element_name or element_name == '*'}
|
99
|
+
|
91
100
|
|
92
101
|
if return_elements.length > 0 then
|
93
102
|
if a.empty? then
|
94
103
|
return_elements.map.with_index {|x,i| filter(x, i+1, attr_search)}
|
95
104
|
else
|
96
|
-
return_elements.map.with_index
|
105
|
+
return_elements.map.with_index do |x,i|
|
106
|
+
rtn_element = filter(x, i+1, attr_search){|e| r = e.xpath(a.join('/'), rlist); r || e }
|
107
|
+
|
108
|
+
rlist << rtn_element
|
109
|
+
rtn_element
|
110
|
+
end
|
97
111
|
end
|
98
112
|
else
|
99
113
|
# strip off the 1st element from the XPath
|
100
114
|
new_xpath = xpath_value[/^\/\/\w+\/(.*)/,1]
|
101
115
|
if new_xpath then
|
102
|
-
self.xpath
|
116
|
+
self.xpath(new_xpath, rlist)
|
103
117
|
end
|
104
118
|
end
|
105
119
|
end
|
106
120
|
|
121
|
+
def scan_match(nodes, element, rlist)
|
122
|
+
nodes.children.each.with_index do |x, i|
|
123
|
+
rlist << x if x.name == element
|
124
|
+
x.xpath('//' + element, rlist) unless x.children.empty?
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
107
128
|
def attributes()
|
108
129
|
@attributes
|
109
130
|
end
|
@@ -133,7 +154,7 @@ class Rexle
|
|
133
154
|
end
|
134
155
|
end
|
135
156
|
|
136
|
-
end
|
157
|
+
end # -- end of element --
|
137
158
|
|
138
159
|
def scan_element(a)
|
139
160
|
|
@@ -199,4 +220,4 @@ class Rexle
|
|
199
220
|
@doc.xpath(path).flatten.compact.length
|
200
221
|
end
|
201
222
|
|
202
|
-
end
|
223
|
+
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.2.
|
4
|
+
version: 0.2.4
|
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-
|
12
|
+
date: 2010-10-25 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|