recordx-parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/recordx-parser.rb +40 -0
- metadata +55 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# file: recordx-parser.rb
|
4
|
+
|
5
|
+
require 'rexleparser'
|
6
|
+
|
7
|
+
class RecordxParser
|
8
|
+
|
9
|
+
def initialize(s)
|
10
|
+
parse(s){|x| yield(x)}
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(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| yield(x)}
|
32
|
+
end
|
33
|
+
|
34
|
+
[root_name, "", {}, [*summary], ['records', "",{}, *records]]
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_a()
|
38
|
+
@a
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recordx-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors: []
|
7
|
+
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-11-15 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/recordx-parser.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage:
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: recordx-parser
|
54
|
+
test_files: []
|
55
|
+
|