rexle 0.4.11 → 0.5.0

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/rexle.rb +28 -7
  2. metadata +21 -1
data/lib/rexle.rb CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  require 'rexml/document'
6
6
  require 'rexleparser'
7
+ require 'dynarex-parser'
8
+ require 'polyrex-parser'
7
9
  include REXML
8
10
 
9
11
  class Rexle
@@ -12,7 +14,7 @@ class Rexle
12
14
 
13
15
  if x then
14
16
  procs = {
15
- String: proc {|x| RexleParser.new(x).to_a},
17
+ String: proc {|x| parse_string(x)},
16
18
  Array: proc {|x| x},
17
19
  :"REXML::Document" => proc {|x| scan_doc x.root}
18
20
  }
@@ -111,7 +113,6 @@ class Rexle
111
113
  end
112
114
  end
113
115
 
114
- #a.shift # added by jr 171110
115
116
  rlist
116
117
  end
117
118
 
@@ -187,8 +188,6 @@ class Rexle
187
188
  end
188
189
  end
189
190
 
190
-
191
-
192
191
  def scan_match(nodes, element, attr_search, condition, rlist)
193
192
  nodes.children.each.with_index do |x, i|
194
193
  if x.name == element
@@ -237,7 +236,7 @@ class Rexle
237
236
 
238
237
  if x then
239
238
  procs = {
240
- String: proc {|x| RexleParser.new(x).to_a},
239
+ String: proc {|x| parse_string(x)},
241
240
  Array: proc {|x| x},
242
241
  :"REXML::Document" => proc {|x| scan_doc x.root}
243
242
  }
@@ -249,6 +248,29 @@ class Rexle
249
248
  @doc = scan_element(*a)
250
249
  self
251
250
  end
251
+
252
+ def parse_string(x)
253
+
254
+ # check if the XML string is a dynarex document
255
+ if x[/<summary>/] then
256
+
257
+ doc = Document.new("<summary>" + x[/(.*?(<\/?summary>)){2}/m,1])
258
+ recordx_type = doc.root.text('recordx_type')
259
+
260
+ if recordx_type then
261
+ procs = {
262
+ 'dynarex' => proc {|x| DynarexParser.new(x).to_a},
263
+ 'polyrex' => proc {|x| PolyrexParser.new(x).to_a}
264
+ }
265
+ procs[recordx_type].call(x)
266
+ else
267
+ RexleParser.new(x).to_a
268
+ end
269
+ else
270
+ RexleParser.new(x).to_a
271
+ end
272
+
273
+ end
252
274
 
253
275
  def root() @doc end
254
276
  def xml()
@@ -288,5 +310,4 @@ class Rexle
288
310
  [node.name, node.text.to_s, attributes, *children]
289
311
  end
290
312
 
291
-
292
- end
313
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -22,6 +22,26 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: dynarex-parser
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: polyrex-parser
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
25
45
  description:
26
46
  email:
27
47
  executables: []