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