polyrex-parser 0.2.1 → 0.2.2
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/polyrex-parser.rb +40 -6
- metadata +2 -2
data/lib/polyrex-parser.rb
CHANGED
@@ -2,14 +2,48 @@
|
|
2
2
|
|
3
3
|
# file: polyrex-parser.rb
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'rexleparser'
|
6
|
+
|
7
|
+
class PolyrexParser
|
6
8
|
|
7
|
-
class PolyrexParser < RecordxParser
|
8
9
|
def initialize(s)
|
9
10
|
@a = parse(s)
|
10
11
|
end
|
11
|
-
|
12
|
-
def
|
13
|
-
|
12
|
+
|
13
|
+
def parse(s)
|
14
|
+
|
15
|
+
s.instance_eval{
|
16
|
+
def fetch_summary()
|
17
|
+
name = 'summary'
|
18
|
+
self.slice(((self =~ /<#{name}>/) + name.length + 2) .. \
|
19
|
+
(self =~ /<\/#{name}>/m) - 1) if self[/<#{name}>/]
|
20
|
+
end
|
21
|
+
def fetch_records()
|
22
|
+
name = 'records'
|
23
|
+
self.slice(((self =~ /<#{name}>/) + name.length + 2) .. \
|
24
|
+
(self =~ /.(?!.*<\/#{name}>)/m) - 1) if self[/<#{name}>/]
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
root_name = s[/<(\w+)/,1]
|
29
|
+
|
30
|
+
summary = RexleParser.new("<summary>#{s.fetch_summary}</summary>").to_a
|
31
|
+
|
32
|
+
raw_records = s.fetch_records
|
33
|
+
records = nil
|
34
|
+
|
35
|
+
if raw_records then
|
36
|
+
node_name = raw_records[/<(\w+)/,1]
|
37
|
+
record_threads = raw_records.strip.split(/(?=<#{node_name}[^>]*>)/).map do |x|
|
38
|
+
Thread.new{ Thread.current[:record] = parse(x) }
|
39
|
+
end
|
40
|
+
records = record_threads.map{|x| x.join; x[:record]}
|
41
|
+
end
|
42
|
+
|
43
|
+
[root_name, "", {}, [*summary], ['records', "",{}, *records]]
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_a()
|
47
|
+
@a
|
14
48
|
end
|
15
|
-
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
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-11-
|
12
|
+
date: 2010-11-16 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|