dynarex-parser 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/dynarex-parser.rb +31 -7
  2. metadata +1 -1
@@ -2,15 +2,39 @@
2
2
 
3
3
  # file: dynarex-parser.rb
4
4
 
5
- require 'recordx-parser'
5
+ require 'rexleparser'
6
+
7
+ class DynarexParser
6
8
 
7
- class DynarexParser < RecordxParser
8
-
9
9
  def initialize(s)
10
10
  @a = parse(s)
11
11
  end
12
-
13
- def fetch_records(a_records)
14
- a_records.map {|x| RexleParser.new(x).to_a}
15
- 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| RexleParser.new(x).to_a}
32
+ end
33
+
34
+ [root_name, "", {}, [*summary], ['records', "",{}, *records]]
35
+ end
36
+
37
+ def to_a()
38
+ @a
39
+ end
16
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynarex-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors: []
7
7