polyrex-parser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/polyrex-parser.rb +3 -32
- metadata +1 -1
data/lib/polyrex-parser.rb
CHANGED
@@ -2,39 +2,10 @@
|
|
2
2
|
|
3
3
|
# file: polyrex-parser.rb
|
4
4
|
|
5
|
-
require '
|
6
|
-
|
7
|
-
class PolyrexParser
|
5
|
+
require 'recordx-parser'
|
8
6
|
|
7
|
+
class PolyrexParser < RecordxParser
|
9
8
|
def initialize(s)
|
10
|
-
@a =
|
11
|
-
end
|
12
|
-
|
13
|
-
def scan_polyrex(s)
|
14
|
-
|
15
|
-
s.instance_eval{
|
16
|
-
def fetch_node(name)
|
17
|
-
self.slice(((self =~ /<#{name}>/) + name.length + 2) .. \
|
18
|
-
(self =~ /<\/#{name}>/) - 1) if self[/<#{name}>/]
|
19
|
-
end
|
20
|
-
}
|
21
|
-
|
22
|
-
root_name = s[/<(\w+)/,1]
|
23
|
-
|
24
|
-
summary = RexleParser.new("<summary>#{s.fetch_node(:summary)}</summary>").to_a
|
25
|
-
|
26
|
-
raw_records = s.fetch_node(:records)
|
27
|
-
records = nil
|
28
|
-
|
29
|
-
if raw_records then
|
30
|
-
node_name = raw_records[/<(\w+)/,1]
|
31
|
-
records = raw_records.strip.split(/(?=<#{node_name}[^>]*>)/).map {|x| scan_polyrex(x)}
|
32
|
-
end
|
33
|
-
|
34
|
-
[summary, records]
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_a()
|
38
|
-
@a
|
9
|
+
@a = super(s){|x| parse(x)}
|
39
10
|
end
|
40
11
|
end
|