polyrex 1.3.1 → 1.3.5
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/polyrex.rb +175 -168
- data.tar.gz.sig +0 -0
- metadata +34 -33
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3413a3c5b270c23b38ac9eb38d7a5db277015cf7c243f417801c1de3eae70b07
|
4
|
+
data.tar.gz: c8efa6bf7eaaf63495be71aa4075d9c4ece28d3e90e9bc78b7f8949a464b8408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04c957f9db524ed3d613174e2526b8a33beeaeda041ea1067e7e4fd68a13b43b1495c7b97ebb01266daa22629632dcd71efb3855fa986e8bdad6fd2f399ead48
|
7
|
+
data.tar.gz: 26a35f2b6f012ece9689c9f5b804d53a1b6b917f36128d6dc7a5244b0ae474520abf97b5b500cc8679ed94097c5865c3373f2db6068d4f92560e6023dc42c012
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/polyrex.rb
CHANGED
@@ -39,7 +39,7 @@ class PolyrexException < Exception
|
|
39
39
|
end
|
40
40
|
|
41
41
|
class Polyrex
|
42
|
-
attr_accessor :summary_fields, :xslt_schema, :id_counter,
|
42
|
+
attr_accessor :summary_fields, :xslt_schema, :id_counter,
|
43
43
|
:schema, :type, :delimiter, :xslt, :format_masks
|
44
44
|
|
45
45
|
def initialize(location=nil, schema: nil, id_counter: '1', debug: false)
|
@@ -47,15 +47,15 @@ class Polyrex
|
|
47
47
|
|
48
48
|
@id_counter, @debug = id_counter, debug
|
49
49
|
@format_masks = []
|
50
|
-
@delimiter = ''
|
50
|
+
@delimiter = ''
|
51
51
|
|
52
|
-
self.method(:schema=).call(schema) if schema
|
53
|
-
|
54
|
-
if location then
|
52
|
+
self.method(:schema=).call(schema) if schema
|
53
|
+
|
54
|
+
if location then
|
55
55
|
|
56
56
|
s, type = RXFHelper.read(location)
|
57
57
|
return import(s) if s =~ /^\<\?polyrex\b/
|
58
|
-
|
58
|
+
|
59
59
|
@local_filepath = location if type == :file or type == :dfs
|
60
60
|
|
61
61
|
openx(s)
|
@@ -70,10 +70,10 @@ class Polyrex
|
|
70
70
|
|
71
71
|
@summary = RecordX.new @doc.root.xpath("summary/*")
|
72
72
|
@summary_fields = @summary.keys
|
73
|
-
|
73
|
+
|
74
74
|
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
@polyrex_xslt = RecordxXSLT.new
|
78
78
|
#@parent_node = @doc.root if @doc
|
79
79
|
end
|
@@ -99,7 +99,7 @@ class Polyrex
|
|
99
99
|
@doc.root.xpath(x).each(&:delete)
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
def delimiter=(separator)
|
104
104
|
|
105
105
|
@delimiter = separator
|
@@ -107,19 +107,23 @@ class Polyrex
|
|
107
107
|
@format_masks.map! do |format_mask|
|
108
108
|
format_mask.to_s.gsub(/\s/, separator)
|
109
109
|
end
|
110
|
-
end
|
111
|
-
|
110
|
+
end
|
111
|
+
|
112
112
|
def each_recursive(parent=self, level=0, &blk)
|
113
|
-
|
113
|
+
|
114
114
|
parent.records.each.with_index do |x, index|
|
115
115
|
|
116
116
|
blk.call(x, parent, level, index) if block_given?
|
117
117
|
|
118
118
|
each_recursive(x, level+1, &blk) if x.records.any?
|
119
|
-
|
119
|
+
|
120
120
|
end
|
121
|
-
|
122
|
-
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def export(filepath)
|
125
|
+
FileX.write filepath, to_s()
|
126
|
+
end
|
123
127
|
|
124
128
|
def record()
|
125
129
|
@parent_node
|
@@ -130,20 +134,20 @@ class Polyrex
|
|
130
134
|
@doc.to_s(options)
|
131
135
|
end
|
132
136
|
|
133
|
-
def save(filepath=nil, opt={}, options: opt, pretty: false)
|
134
|
-
|
137
|
+
def save(filepath=nil, opt={}, options: opt, pretty: false)
|
138
|
+
|
135
139
|
refresh_summary
|
136
140
|
filepath ||= @local_filepath
|
137
141
|
@local_filepath = filepath
|
138
|
-
|
142
|
+
|
139
143
|
options.merge!({pretty: pretty}) if options.empty?
|
140
144
|
xml = @doc.to_s(options)
|
141
|
-
|
145
|
+
|
142
146
|
buffer = block_given? ? yield(xml) : xml
|
143
|
-
|
147
|
+
FileX.write filepath, buffer
|
144
148
|
end
|
145
|
-
|
146
|
-
# -- start of crud methods --
|
149
|
+
|
150
|
+
# -- start of crud methods --
|
147
151
|
|
148
152
|
def find_by_id(id)
|
149
153
|
@parent_node = @doc.root.element("//[@id='#{id}']")
|
@@ -154,52 +158,52 @@ class Polyrex
|
|
154
158
|
@parent_node = @doc.root.element("//[@id='#{id}']")
|
155
159
|
self
|
156
160
|
end
|
157
|
-
|
161
|
+
|
158
162
|
def order=(val)
|
159
163
|
@order = val.to_s
|
160
164
|
end
|
161
165
|
|
162
166
|
# -- end of crud methods --
|
163
|
-
|
167
|
+
|
164
168
|
# -- start of full text edit methods
|
165
169
|
def format_masks
|
166
170
|
@format_masks
|
167
|
-
end
|
168
|
-
|
171
|
+
end
|
172
|
+
|
169
173
|
def parse(x=nil, options={})
|
170
174
|
|
171
175
|
buffer, type = RXFHelper.read(x)
|
172
|
-
|
176
|
+
|
173
177
|
if type == :unknown and buffer.lines.length <= 1 then
|
174
178
|
raise PolyrexException, 'File not found: ' + x.inspect
|
175
179
|
end
|
176
|
-
|
177
|
-
buffer = yield if block_given?
|
180
|
+
|
181
|
+
buffer = yield if block_given?
|
178
182
|
string_parse buffer.clone, options
|
179
183
|
|
180
184
|
self
|
181
|
-
end
|
182
|
-
|
185
|
+
end
|
186
|
+
|
183
187
|
alias import parse
|
184
188
|
|
185
189
|
def element(s)
|
186
190
|
@doc.root.element(s)
|
187
191
|
end
|
188
|
-
|
192
|
+
|
189
193
|
def leaf_nodes_to_dx()
|
190
|
-
|
194
|
+
|
191
195
|
schema, record_name = @summary.schema\
|
192
196
|
.match(/([^\/]+\/([^\/]+)\[[^\[]+$)/).captures
|
193
|
-
|
197
|
+
|
194
198
|
xml = RexleBuilder.new
|
195
199
|
|
196
200
|
xml.items do
|
197
201
|
xml.summary do
|
198
202
|
xml.schema schema.sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
|
199
203
|
end
|
200
|
-
xml.records
|
204
|
+
xml.records
|
201
205
|
end
|
202
|
-
|
206
|
+
|
203
207
|
doc = Rexle.new xml.to_a
|
204
208
|
body = doc.root.element 'records'
|
205
209
|
a = self.xpath('//' + record_name)
|
@@ -210,43 +214,43 @@ class Polyrex
|
|
210
214
|
|
211
215
|
make_dynarex doc.root
|
212
216
|
end
|
213
|
-
|
217
|
+
|
214
218
|
def records
|
215
219
|
|
216
|
-
@doc.root.xpath("records/*").map do |node|
|
220
|
+
@doc.root.xpath("records/*").map do |node|
|
217
221
|
Kernel.const_get(node.name.capitalize).new node, id: @id_counter
|
218
222
|
end
|
219
|
-
|
223
|
+
|
220
224
|
end
|
221
225
|
|
222
226
|
def rxpath(s)
|
223
|
-
|
227
|
+
|
224
228
|
a = @doc.root.xpath s.split('/').map \
|
225
229
|
{|x| x.sub('[','[summary/').prepend('records/')}.join('/')
|
226
|
-
|
227
|
-
a.map do |node|
|
230
|
+
|
231
|
+
a.map do |node|
|
228
232
|
Kernel.const_get(node.name.capitalize).new node, id: node.attributes[:id]
|
229
233
|
end
|
230
234
|
|
231
235
|
end
|
232
|
-
|
236
|
+
|
233
237
|
def schema=(s)
|
234
238
|
|
235
239
|
if s =~ /gem\[/ then
|
236
|
-
raise PolyrexException, "invalid schema: cannot contain the " +
|
240
|
+
raise PolyrexException, "invalid schema: cannot contain the " +
|
237
241
|
"word gem as a record name"
|
238
242
|
end
|
239
|
-
|
243
|
+
|
240
244
|
openx(s)
|
241
245
|
|
242
246
|
summary_h = Hash[*@doc.root.xpath("summary/*").\
|
243
247
|
map {|x| [x.name, x.text.to_s]}.flatten]
|
244
248
|
|
245
249
|
@summary = RecordX.new summary_h
|
246
|
-
@summary_fields = summary_h.keys.map(&:to_sym)
|
250
|
+
@summary_fields = summary_h.keys.map(&:to_sym)
|
247
251
|
self
|
248
252
|
end
|
249
|
-
|
253
|
+
|
250
254
|
def summary
|
251
255
|
@summary
|
252
256
|
end
|
@@ -254,7 +258,7 @@ class Polyrex
|
|
254
258
|
def to_a()
|
255
259
|
recordx_map @doc.root
|
256
260
|
end
|
257
|
-
|
261
|
+
|
258
262
|
def to_dynarex()
|
259
263
|
|
260
264
|
root = @doc.root.deep_clone
|
@@ -263,17 +267,17 @@ class Polyrex
|
|
263
267
|
#summary.delete('format_mask')
|
264
268
|
#summary.element('recordx_type').text = 'dynarex'
|
265
269
|
|
266
|
-
summary.add root.element('records/*/summary/format_mask').clone
|
270
|
+
summary.add root.element('records/*/summary/format_mask').clone
|
267
271
|
e = summary.element('schema')
|
268
272
|
e.text = e.text[/[^\/]+\/[^\/]+/].sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
|
269
273
|
|
270
274
|
make_dynarex(root)
|
271
275
|
end
|
272
|
-
|
276
|
+
|
273
277
|
def to_opml()
|
274
|
-
|
278
|
+
|
275
279
|
puts '@schema: ' + @schema.inspect if @debug
|
276
|
-
|
280
|
+
|
277
281
|
head, body = @schema.split(/(?<=\])/,2)
|
278
282
|
schema_body = body.gsub(/(?<=\[)[^\]]+/) do |x|
|
279
283
|
x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
|
@@ -284,16 +288,16 @@ class Polyrex
|
|
284
288
|
|
285
289
|
puts 'schema_body: ' + schema_body.inspect if @debug
|
286
290
|
puts 'schema_head: ' + schema_head.inspect if @debug
|
287
|
-
xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
|
291
|
+
xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
|
288
292
|
schema_body.gsub(/\w+(?=\[)/,'outline')\
|
289
293
|
.sub(/\/(\w+)(?=\[)/,'/body>outline')
|
290
|
-
|
294
|
+
|
291
295
|
puts 'xslt_schema: ' + xslt_schema.inspect if @debug
|
292
|
-
|
296
|
+
|
293
297
|
recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
|
294
|
-
|
295
|
-
Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
|
296
|
-
|
298
|
+
|
299
|
+
Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
|
300
|
+
|
297
301
|
end
|
298
302
|
|
299
303
|
def to_s(header: true)
|
@@ -305,11 +309,12 @@ class Polyrex
|
|
305
309
|
summary = item.element 'summary'
|
306
310
|
format_mask = summary.text('format_mask').to_s
|
307
311
|
line = format_mask.gsub(/\[![^\]]+\]/){|x| summary.text(x[2..-2]).to_s}
|
312
|
+
puts 'line: ' + line.inspect if @debug
|
308
313
|
|
309
|
-
|
310
|
-
|
311
|
-
if
|
312
|
-
line = line + "\n" + build(
|
314
|
+
recordsx = item.element('records').elements.to_a
|
315
|
+
|
316
|
+
if recordsx.length > 0 then
|
317
|
+
line = line + "\n" + build(recordsx, indent + 1).join("\n")
|
313
318
|
end
|
314
319
|
(' ' * indent) + line
|
315
320
|
end
|
@@ -329,9 +334,9 @@ class Polyrex
|
|
329
334
|
declaration = @raw_header
|
330
335
|
else
|
331
336
|
|
332
|
-
smry_fields = %i(schema)
|
337
|
+
smry_fields = %i(schema)
|
333
338
|
if self.delimiter.length > 0 then
|
334
|
-
smry_fields << :delimiter
|
339
|
+
smry_fields << :delimiter
|
335
340
|
else
|
336
341
|
smry_fields << :format_mask
|
337
342
|
end
|
@@ -342,25 +347,25 @@ class Polyrex
|
|
342
347
|
declaration = %Q(<?polyrex %s?>\n) % s
|
343
348
|
end
|
344
349
|
|
345
|
-
docheader = declaration + sumry
|
350
|
+
docheader = declaration + "\n" + sumry
|
346
351
|
out = build(self.records).join("\n")
|
347
352
|
header ? docheader + "\n" + out : out
|
348
|
-
|
353
|
+
|
349
354
|
end
|
350
|
-
|
355
|
+
|
351
356
|
def to_tree()
|
352
|
-
|
357
|
+
|
353
358
|
s = @schema.gsub(/(?<=\[)[^\]]+/) do |x|
|
354
359
|
x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
|
355
360
|
end
|
356
361
|
|
357
|
-
xslt_schema = s.gsub(/\w+(?=\[)/,'item').sub(/^\w+/,'tree')
|
358
|
-
recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
|
359
|
-
Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
|
360
|
-
|
361
|
-
end
|
362
|
+
xslt_schema = s.gsub(/\w+(?=\[)/,'item').sub(/^\w+/,'tree')
|
363
|
+
recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
|
364
|
+
Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
|
365
|
+
|
366
|
+
end
|
362
367
|
|
363
|
-
def to_xslt()
|
368
|
+
def to_xslt()
|
364
369
|
@polyrex_xslt.schema = @schema
|
365
370
|
@polyrex_xslt.to_xslt
|
366
371
|
end
|
@@ -375,26 +380,26 @@ class Polyrex
|
|
375
380
|
end
|
376
381
|
|
377
382
|
def xslt=(value)
|
378
|
-
|
383
|
+
|
379
384
|
@summary.xslt = value
|
380
385
|
|
381
|
-
end
|
382
|
-
|
386
|
+
end
|
387
|
+
|
383
388
|
def xslt_schema=(s)
|
384
389
|
@polyrex_xslt.xslt_schema = s
|
385
390
|
self
|
386
391
|
end
|
387
|
-
|
392
|
+
|
388
393
|
protected
|
389
|
-
|
394
|
+
|
390
395
|
def doc()
|
391
396
|
@doc
|
392
397
|
end
|
393
398
|
|
394
399
|
private
|
395
|
-
|
400
|
+
|
396
401
|
def make_dynarex(root)
|
397
|
-
|
402
|
+
|
398
403
|
root.delete('summary/recordx_type')
|
399
404
|
root.delete('summary/format_mask')
|
400
405
|
root.xpath('records/*/summary/format_mask').each(&:delete)
|
@@ -428,8 +433,8 @@ xsl_buffer = '
|
|
428
433
|
|
429
434
|
buffer = Rexslt.new(xsl_buffer, root.xml).to_s
|
430
435
|
Dynarex.new buffer
|
431
|
-
|
432
|
-
end
|
436
|
+
|
437
|
+
end
|
433
438
|
|
434
439
|
def refresh_records(records, fields, level)
|
435
440
|
|
@@ -464,10 +469,10 @@ xsl_buffer = '
|
|
464
469
|
flatten.map(&:to_sym)
|
465
470
|
summary = field_names.map {|x| "<%s/>" % x}.join
|
466
471
|
end
|
467
|
-
|
472
|
+
|
468
473
|
summary << "<recordx_type>polyrex</recordx_type><schema>#{schema}</schema>"
|
469
474
|
#----
|
470
|
-
|
475
|
+
|
471
476
|
@schema = schema
|
472
477
|
@id_counter = '0'
|
473
478
|
|
@@ -476,12 +481,12 @@ xsl_buffer = '
|
|
476
481
|
[root_name, (summary || '') , root_name])
|
477
482
|
|
478
483
|
end
|
479
|
-
|
484
|
+
|
480
485
|
def recordx_map(node)
|
481
|
-
|
486
|
+
|
482
487
|
# get the summary
|
483
488
|
fields = node.xpath('summary/*').map do |x|
|
484
|
-
next if %w(schema format_mask recordx_type).include? x.name
|
489
|
+
next if %w(schema format_mask recordx_type).include? x.name
|
485
490
|
r = x.text.to_s.gsub(/^[\n\s]+/,'').length > 0 ? x.text.to_s : \
|
486
491
|
x.cdatas.join.strip
|
487
492
|
r
|
@@ -489,28 +494,28 @@ xsl_buffer = '
|
|
489
494
|
|
490
495
|
# get the records
|
491
496
|
a = node.xpath('records/*').map {|x| recordx_map x}
|
492
|
-
|
497
|
+
|
493
498
|
[fields.compact, a]
|
494
|
-
end
|
495
|
-
|
499
|
+
end
|
500
|
+
|
496
501
|
def string_parse(buffer, options={})
|
497
502
|
|
498
503
|
@raw_header = buffer.slice!(/<\?polyrex[^>]+>/)
|
499
|
-
|
504
|
+
|
500
505
|
if @raw_header then
|
501
506
|
header = @raw_header[/<?polyrex (.*)?>/,1]
|
502
507
|
|
503
508
|
r1 = /([\w\[\]\-]+\s*\=\s*'[^']*)'/
|
504
509
|
r2 = /([\w\[\]\-]+\s*\=\s*"[^"]*)"/
|
505
510
|
|
506
|
-
a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
|
511
|
+
a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
|
512
|
+
|
507
513
|
|
508
|
-
|
509
514
|
a.each do |x|
|
510
|
-
|
515
|
+
|
511
516
|
attr, val = x.split(/\s*=\s*["']/,2)
|
512
517
|
|
513
|
-
i = attr[/format_masks?\[(\d+)/,1]
|
518
|
+
i = attr[/format_masks?\[(\d+)/,1]
|
514
519
|
|
515
520
|
if i then
|
516
521
|
|
@@ -522,28 +527,28 @@ xsl_buffer = '
|
|
522
527
|
end
|
523
528
|
end
|
524
529
|
end
|
525
|
-
|
530
|
+
|
526
531
|
options.each do |k,v|
|
527
|
-
|
532
|
+
|
528
533
|
if options[k] then
|
529
534
|
a.delete a.assoc(k)
|
530
535
|
self.method(((k.to_s) + '=').to_sym).call(options[k])
|
531
536
|
end
|
532
|
-
|
537
|
+
|
533
538
|
end
|
534
|
-
|
539
|
+
|
535
540
|
end
|
536
541
|
|
537
|
-
raw_lines = buffer.
|
542
|
+
raw_lines = buffer.lstrip.lines.map(&:chomp)
|
538
543
|
|
539
544
|
raw_summary = schema[/^\w+\[([^\]]+)/,1]
|
540
545
|
|
541
546
|
if raw_summary then
|
542
547
|
a_summary = raw_summary.split(',').map(&:strip)
|
543
548
|
|
544
|
-
while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
|
549
|
+
while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
|
545
550
|
|
546
|
-
label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
|
551
|
+
label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
|
547
552
|
@summary.send((label + '=').to_sym, val)
|
548
553
|
end
|
549
554
|
|
@@ -555,53 +560,55 @@ xsl_buffer = '
|
|
555
560
|
@parent_node = records.parent
|
556
561
|
records.delete
|
557
562
|
|
558
|
-
|
563
|
+
puts 'raw_lines: ' + raw_lines.inspect if @debug
|
564
|
+
lines = LineTree.new(raw_lines.join("\n"), ignore_label: true).to_a
|
565
|
+
puts 'lines: ' + lines.inspect if @debug
|
559
566
|
@parent_node.root.add format_line!( lines)
|
560
567
|
|
561
|
-
end
|
562
|
-
|
568
|
+
end
|
569
|
+
|
563
570
|
def unescape(s)
|
564
571
|
r = s.gsub('<', '<').gsub('>','>')
|
565
572
|
end
|
566
|
-
|
573
|
+
|
567
574
|
def load_handlers(schema)
|
568
575
|
|
569
|
-
objects = PolyrexObjects.new(schema, debug: @debug)
|
576
|
+
objects = PolyrexObjects.new(schema, debug: @debug)
|
570
577
|
h = objects.to_h
|
571
578
|
puts 'h: ' + h.inspect if @debug
|
572
579
|
@objects = h.inject({}){|r,x| r.merge x[0].downcase => x[-1]}
|
573
580
|
|
574
581
|
@objects_a = objects.to_a
|
575
582
|
attach_create_handlers(@objects.keys)
|
576
|
-
#attach_edit_handlers(@objects)
|
583
|
+
#attach_edit_handlers(@objects)
|
577
584
|
|
578
585
|
end
|
579
|
-
|
586
|
+
|
580
587
|
def format_line!(a, i=0)
|
581
588
|
|
582
589
|
records = Rexle::Element.new('records')
|
583
|
-
|
590
|
+
|
584
591
|
# add code here for rowx
|
585
592
|
@field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
|
586
593
|
.flatten.map(&:to_sym)
|
587
594
|
|
588
595
|
rowx_fields = a.map{|x| x.first[/^\w+(?=:)/].to_s.to_sym}.uniq
|
589
|
-
|
596
|
+
|
590
597
|
records = if (@field_names & rowx_fields).length >= 2 then
|
591
598
|
# rowx implementation still to-do
|
592
599
|
#vertical_fiedlparse(records, a, i)
|
593
600
|
else
|
594
601
|
horizontal_fieldparse(records, a, i)
|
595
602
|
end
|
596
|
-
|
603
|
+
|
597
604
|
end
|
598
|
-
|
599
|
-
|
605
|
+
|
606
|
+
|
600
607
|
# -- end of full text edit methods
|
601
|
-
|
608
|
+
|
602
609
|
def horizontal_fieldparse(records, a, i)
|
603
610
|
|
604
|
-
a.each do |x|
|
611
|
+
a.each do |x|
|
605
612
|
|
606
613
|
unless @recordx[i] then
|
607
614
|
@recordx[i] = @recordx[-1].clone
|
@@ -613,28 +620,28 @@ xsl_buffer = '
|
|
613
620
|
|
614
621
|
|
615
622
|
line = raw_line
|
616
|
-
|
623
|
+
|
617
624
|
if line[/\w+\s*---/] then
|
618
625
|
|
619
626
|
node_name = line.sub(/\s*---/,'')
|
620
627
|
ynode = Rexle::Element.new(node_name).add_text("---\n" + x.join("\n"))
|
621
|
-
|
628
|
+
|
622
629
|
summary.add ynode
|
623
630
|
next
|
624
631
|
end
|
625
|
-
|
632
|
+
|
626
633
|
puts '@schema: ' + @schema.inspect if @debug
|
627
634
|
schema_a = @schema.split('/')[1..-1]
|
628
|
-
|
635
|
+
|
629
636
|
if @debug then
|
630
637
|
puts 'schema_a: ' + schema_a.inspect
|
631
638
|
puts 'i: ' + i.inspect
|
632
639
|
end
|
633
|
-
|
640
|
+
|
634
641
|
unless @format_masks[i][/^\(.*\)$/] then
|
635
642
|
|
636
643
|
@field_names, field_values = RXRawLineParser.new(format_masks[i])\
|
637
|
-
.parse(line)
|
644
|
+
.parse(line)
|
638
645
|
|
639
646
|
@field_names = schema_a[i] ? \
|
640
647
|
schema_a[i][/\[([^\]]+)/,1].split(/\s*,\s*/).map(&:to_sym) : \
|
@@ -649,12 +656,12 @@ xsl_buffer = '
|
|
649
656
|
|
650
657
|
pattern = patterns.detect {|x| line.match(/#{x}/)}
|
651
658
|
i = patterns.index(pattern)
|
652
|
-
|
659
|
+
|
653
660
|
@field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
|
654
661
|
.flatten.map(&:to_sym)
|
655
662
|
|
656
|
-
field_values = line.match(/#{pattern}/).captures
|
657
|
-
|
663
|
+
field_values = line.match(/#{pattern}/).captures
|
664
|
+
|
658
665
|
end
|
659
666
|
|
660
667
|
@id_counter.succ!
|
@@ -664,9 +671,9 @@ xsl_buffer = '
|
|
664
671
|
record.add_attribute(id: @id_counter.clone)
|
665
672
|
summary = Rexle::Element.new('summary')
|
666
673
|
|
667
|
-
@field_names.zip(field_values).each do |name, value|
|
674
|
+
@field_names.zip(field_values).each do |name, value|
|
668
675
|
field = Rexle::Element.new(name.to_s)
|
669
|
-
field.text = value
|
676
|
+
field.text = value
|
670
677
|
summary.add field
|
671
678
|
end
|
672
679
|
|
@@ -678,42 +685,42 @@ xsl_buffer = '
|
|
678
685
|
summary.add Rexle::Element.new('format_mask').add_text(format_mask)
|
679
686
|
summary.add Rexle::Element.new('schema').add_text(schema)
|
680
687
|
summary.add Rexle::Element.new('recordx_type').add_text('polyrex')
|
681
|
-
|
688
|
+
|
682
689
|
record.add summary
|
683
690
|
child_records = format_line!(x, i+1)
|
684
691
|
|
685
692
|
record.add child_records
|
686
693
|
records.add record
|
687
694
|
end
|
688
|
-
|
695
|
+
|
689
696
|
records
|
690
697
|
end
|
691
698
|
|
692
699
|
def attach_create_handlers(names)
|
693
700
|
methodx = names.map do |name|
|
694
701
|
%Q(
|
695
|
-
def create_#{name.downcase}(params, &blk)
|
702
|
+
def create_#{name.downcase}(params, &blk)
|
696
703
|
self.create.#{name.downcase}(params, &blk)
|
697
704
|
end
|
698
705
|
)
|
699
706
|
end
|
700
707
|
|
701
708
|
self.instance_eval(methodx.join("\n"))
|
702
|
-
|
709
|
+
|
703
710
|
end
|
704
|
-
|
711
|
+
|
705
712
|
def attach_edit_handlers(objects)
|
706
713
|
objects.keys.each do |name|
|
707
714
|
self.instance_eval(
|
708
715
|
%Q(
|
709
|
-
def #{name.downcase}()
|
716
|
+
def #{name.downcase}()
|
710
717
|
@objects['#{name}'].new(@parent_node, id: @id)
|
711
718
|
end
|
712
719
|
))
|
713
720
|
end
|
714
|
-
|
721
|
+
|
715
722
|
end
|
716
|
-
|
723
|
+
|
717
724
|
def openx(s)
|
718
725
|
|
719
726
|
if s[/</] # xml
|
@@ -721,9 +728,9 @@ xsl_buffer = '
|
|
721
728
|
elsif s[/\[/] then # schema
|
722
729
|
buffer = polyrex_new s
|
723
730
|
elsif s[/^https?:\/\//] then # url
|
724
|
-
buffer = open(s, 'UserAgent' => 'Polyrex-Reader').read
|
731
|
+
buffer = URI.open(s, 'UserAgent' => 'Polyrex-Reader').read
|
725
732
|
else # local file
|
726
|
-
buffer =
|
733
|
+
buffer = FileX.read s
|
727
734
|
@local_filepath = s
|
728
735
|
end
|
729
736
|
|
@@ -731,9 +738,9 @@ xsl_buffer = '
|
|
731
738
|
@doc = Rexle.new buffer
|
732
739
|
|
733
740
|
schema = @doc.root.text('summary/schema').to_s
|
734
|
-
|
741
|
+
|
735
742
|
if schema.nil? then
|
736
|
-
schema = PolyrexSchema.new.parse(buffer).to_schema
|
743
|
+
schema = PolyrexSchema.new.parse(buffer).to_schema
|
737
744
|
e = @doc.root.element('summary')
|
738
745
|
e.add Rexle::Element.new('schema').add_text(schema)
|
739
746
|
end
|
@@ -756,7 +763,7 @@ xsl_buffer = '
|
|
756
763
|
@parent_node = @doc.root.element('records')
|
757
764
|
|
758
765
|
end
|
759
|
-
|
766
|
+
|
760
767
|
def regexify_fmask(f)
|
761
768
|
|
762
769
|
a = f.split(/(?=\[!\w+\])/).map do |x|
|
@@ -773,45 +780,45 @@ xsl_buffer = '
|
|
773
780
|
end
|
774
781
|
end
|
775
782
|
|
776
|
-
a.join
|
783
|
+
a.join
|
777
784
|
end
|
778
|
-
|
785
|
+
|
779
786
|
def tail_map(a)
|
780
787
|
[a] + (a.length > 1 ? tail_map(a[0..-2]) : [])
|
781
788
|
end
|
782
|
-
|
789
|
+
|
783
790
|
|
784
791
|
def load_find_by(schema)
|
785
792
|
|
786
793
|
a = PolyrexObjectMethods.new(schema).to_a
|
787
794
|
|
788
|
-
methodx = a.map do |class_name, methods|
|
789
|
-
|
795
|
+
methodx = a.map do |class_name, methods|
|
796
|
+
|
790
797
|
class_name.downcase!
|
791
|
-
|
792
|
-
methods.map do |method_name|
|
793
|
-
|
798
|
+
|
799
|
+
methods.map do |method_name|
|
800
|
+
|
794
801
|
xpath = %Q(@doc.root.element("//%s[summary/%s='\#\{val\}']")) % \
|
795
802
|
[class_name, method_name]
|
796
803
|
xpath2 = %Q(@doc.root.xpath("//%s[summary/%s='\#\{val\}']")) % \
|
797
804
|
[class_name, method_name]
|
798
|
-
|
799
|
-
"def find_by_#{class_name}_#{method_name}(val)
|
800
|
-
|
805
|
+
|
806
|
+
"def find_by_#{class_name}_#{method_name}(val)
|
807
|
+
|
801
808
|
node = #{xpath}
|
802
|
-
|
809
|
+
|
803
810
|
if node then
|
804
811
|
Kernel.const_get(node.name.capitalize).new node, id: @id
|
805
812
|
else
|
806
813
|
nil
|
807
814
|
end
|
808
|
-
|
815
|
+
|
809
816
|
end
|
810
817
|
|
811
|
-
def find_all_by_#{class_name}_#{method_name}(val)
|
812
|
-
|
818
|
+
def find_all_by_#{class_name}_#{method_name}(val)
|
819
|
+
|
813
820
|
nodes = #{xpath2}
|
814
|
-
|
821
|
+
|
815
822
|
if nodes then
|
816
823
|
nodes.map do |node|
|
817
824
|
Kernel.const_get(node.name.capitalize).new node, id: @id
|
@@ -819,35 +826,35 @@ xsl_buffer = '
|
|
819
826
|
else
|
820
827
|
nil
|
821
828
|
end
|
822
|
-
|
823
|
-
end
|
829
|
+
|
830
|
+
end
|
824
831
|
"
|
825
|
-
end
|
832
|
+
end
|
826
833
|
end
|
827
834
|
|
828
835
|
self.instance_eval methodx.join("\n")
|
829
836
|
end
|
830
837
|
|
831
838
|
|
832
|
-
# refreshes the XML document with any new modification from
|
839
|
+
# refreshes the XML document with any new modification from
|
833
840
|
# the summary object
|
834
841
|
def refresh_summary()
|
835
|
-
|
836
|
-
summary = @doc.root.element('summary')
|
842
|
+
|
843
|
+
summary = @doc.root.element('summary')
|
837
844
|
@summary.to_h.each do |k,v|
|
838
|
-
|
845
|
+
|
839
846
|
puts "k: %s; v: %s" % [k, v] if @debug
|
840
847
|
e = summary.element(k.to_s)
|
841
848
|
if e then
|
842
849
|
e.text = v
|
843
850
|
else
|
844
|
-
summary.add Rexle::Element.new(k.to_s).add_text(v)
|
851
|
+
summary.add Rexle::Element.new(k.to_s).add_text(v)
|
845
852
|
end
|
846
853
|
end
|
847
|
-
|
854
|
+
|
848
855
|
if @summary.xslt then
|
849
|
-
@doc.instructions = [['xml-stylesheet',
|
850
|
-
"title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
|
856
|
+
@doc.instructions = [['xml-stylesheet',
|
857
|
+
"title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
|
851
858
|
end
|
852
859
|
end
|
853
860
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,31 +11,31 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwNTI0MTI1MjMzWhcN
|
15
|
+
MjIwNTI0MTI1MjMzWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDxKAjh
|
17
|
+
s6uPs8gcMaoia91NWkBsYkIRp98yXB/MeTcAcK+jM3Y3jbKfbsOa1QVETY+KNZPH
|
18
|
+
byDLynjQE7xOQhZjMrtDB128+iWT+fCvF/OQS0tMMT5ki3qHQDJSqUfxKngwK9p2
|
19
|
+
TlV4EVRaejuPYwGvXxb8qmx9jrR9S3HZVQMHd6aMNAwBb1ZNkSQymWQeEoM+45Un
|
20
|
+
pN3XHGEd2zejUOLNrSiZbBvq5fMb/V2a6LPAfg2WvZzWSZgl4jPjVtvUZVp1BUaU
|
21
|
+
YAXBUsKZ77FC6jR9lb+9iVJAwDTdsI2G6pX5W8EZG0L7i9jeLMQB8bCCzu2zlAhc
|
22
|
+
YJ06owu1LJhPWSxm/3aw6JTKQx0hFepF4mUKHe5iRhDgsVhHNkopzOCQ4JwwHu8G
|
23
|
+
PDi1kUQcFVVkWxRr/m/GRQFkYVn3omgIBMWp/JB8mmevqZ5gaCKvHF55wmDpFzyJ
|
24
|
+
cPDfCtP/wl8wqf363VQdgiru7EcgxQFtPgx6PyMNzfouhRhkBZIY7wYgROkCAwEA
|
25
|
+
AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUcuJiQueO
|
26
|
+
q5BdutOcNGPDMgOla5kwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
27
|
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEA1AnaW09JSrJOdlLTeiItH/Mfj6vcAuodI4Ys3PCh
|
29
|
+
UfQsIJUedcMysvo+6J0M+hEYL02w6ynWahcQbzvYPr+NwV/8FqMGGAyDpBSaLtrz
|
30
|
+
9J4cxy4p/mq2dF2lEsCUNoSBWvDpvQI4c2w79/gpWE+w0abHyX97r3N2wWv/OiwV
|
31
|
+
u06GMpESpRj4RAhhy88aDhGDUfMWd+nZ20gWcs2YR1yJf/JyaDfRcOFqLMgVw35Y
|
32
|
+
oQhEZldZrsYsF4FNEBmH2mx2iLq6VbCyZZ3M6jsIHUEDZdrDjbs8ejPvWfEdTW+1
|
33
|
+
x7007qRZCfLvIsqAf7GViMWXgbiv0ZFSKgV7qtK0IgVBg0NDor3xc9w/3VLqshTZ
|
34
|
+
jIqQb9u4Zkhtsp+Ly/HVroN0cylu1t/el2qILTDOkyKnAikvhKpX1wujv+VVqWwd
|
35
|
+
rivEdfkvT/8GV5Nip0lSS+cuk20UhOdJR9QIcCJp0QL4NUik9VYljGbQbQQS6Isc
|
36
|
+
iIwZ6uFJfcp9SWBRrSZmlI52
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: polyrex-objects
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
version: '1.0'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.0.
|
49
|
+
version: 1.0.3
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version: '1.0'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.0.
|
59
|
+
version: 1.0.3
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: polyrex-object-methods
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,22 +103,22 @@ dependencies:
|
|
103
103
|
requirements:
|
104
104
|
- - "~>"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '1.
|
106
|
+
version: '1.9'
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.
|
109
|
+
version: 1.9.1
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '1.
|
116
|
+
version: '1.9'
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version: 1.
|
119
|
+
version: 1.9.1
|
120
120
|
description:
|
121
|
-
email:
|
121
|
+
email: digital.robertson@gmail.com
|
122
122
|
executables: []
|
123
123
|
extensions: []
|
124
124
|
extra_rdoc_files: []
|
@@ -143,8 +143,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.7.10
|
147
148
|
signing_key:
|
148
149
|
specification_version: 4
|
149
|
-
summary: A flavour of XML for storing and
|
150
|
+
summary: A flavour of XML for storing and retrieving records in a Polyrex hierarchy
|
150
151
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|