polyrex 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/polyrex.rb +161 -161
  4. data.tar.gz.sig +0 -0
  5. metadata +9 -8
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78c884051d6c0b1950f1d02849428a0a64cdc9832adcaf780e99bb45821450aa
4
- data.tar.gz: 2b1a471d556dda7ba64a178aeacdf357a7047bfc8f7008bba15c3745b3f7cddb
3
+ metadata.gz: 5e211b56546f7a7d8cc51eff031d5e404ae3d6fc6f7c3082bac158e88fc80f3e
4
+ data.tar.gz: fde6175c6355d803c5c31f7a49105cbb9ef27ad1b83daf702fcd4a6c144b631f
5
5
  SHA512:
6
- metadata.gz: a4c1bbb5c8e1d584c8dd61f65e11244ffd335dbdfcf3f21672667d98cb8926773c4cb55d3496a1e00ca4df2621d7ffcb2b4f1d34fb65164c1ad9051e635035d2
7
- data.tar.gz: 02b2d2878d9c4f99f8000df5db5094bcc29a30d14ea8d8e584b4dc51672d286f6d89cfdeb1913b4b98c6fe3eef46cbe9474843b6a29cec005920f5bc7d5cba8d
6
+ metadata.gz: 821c0da30fb333a44418cf8cbb96789ea9e5e216646d33dee374461db182f54c9df59ba57ac56e2c2050053f31ad829ea8f00ce4d3b0982fd7ca1bac378042bb
7
+ data.tar.gz: '0785691bdae1f3e99665b1c3600e5ddce7027ef35ecd8eabea1ab98ae02ef33aaf77ceba456a3729be1d6c4ae0e7cb0c0e2bb1865f98ff63da1790dc0a6bf436'
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,18 +107,18 @@ 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
-
121
+
122
122
  end
123
123
 
124
124
  def export(filepath)
@@ -134,20 +134,20 @@ class Polyrex
134
134
  @doc.to_s(options)
135
135
  end
136
136
 
137
- def save(filepath=nil, opt={}, options: opt, pretty: false)
138
-
137
+ def save(filepath=nil, opt={}, options: opt, pretty: false)
138
+
139
139
  refresh_summary
140
140
  filepath ||= @local_filepath
141
141
  @local_filepath = filepath
142
-
142
+
143
143
  options.merge!({pretty: pretty}) if options.empty?
144
144
  xml = @doc.to_s(options)
145
-
145
+
146
146
  buffer = block_given? ? yield(xml) : xml
147
- File.open(filepath,'w'){|f| f.write buffer}
147
+ File.open(filepath,'w'){|f| f.write buffer}
148
148
  end
149
-
150
- # -- start of crud methods --
149
+
150
+ # -- start of crud methods --
151
151
 
152
152
  def find_by_id(id)
153
153
  @parent_node = @doc.root.element("//[@id='#{id}']")
@@ -158,52 +158,52 @@ class Polyrex
158
158
  @parent_node = @doc.root.element("//[@id='#{id}']")
159
159
  self
160
160
  end
161
-
161
+
162
162
  def order=(val)
163
163
  @order = val.to_s
164
164
  end
165
165
 
166
166
  # -- end of crud methods --
167
-
167
+
168
168
  # -- start of full text edit methods
169
169
  def format_masks
170
170
  @format_masks
171
- end
172
-
171
+ end
172
+
173
173
  def parse(x=nil, options={})
174
174
 
175
175
  buffer, type = RXFHelper.read(x)
176
-
176
+
177
177
  if type == :unknown and buffer.lines.length <= 1 then
178
178
  raise PolyrexException, 'File not found: ' + x.inspect
179
179
  end
180
-
181
- buffer = yield if block_given?
180
+
181
+ buffer = yield if block_given?
182
182
  string_parse buffer.clone, options
183
183
 
184
184
  self
185
- end
186
-
185
+ end
186
+
187
187
  alias import parse
188
188
 
189
189
  def element(s)
190
190
  @doc.root.element(s)
191
191
  end
192
-
192
+
193
193
  def leaf_nodes_to_dx()
194
-
194
+
195
195
  schema, record_name = @summary.schema\
196
196
  .match(/([^\/]+\/([^\/]+)\[[^\[]+$)/).captures
197
-
197
+
198
198
  xml = RexleBuilder.new
199
199
 
200
200
  xml.items do
201
201
  xml.summary do
202
202
  xml.schema schema.sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
203
203
  end
204
- xml.records
204
+ xml.records
205
205
  end
206
-
206
+
207
207
  doc = Rexle.new xml.to_a
208
208
  body = doc.root.element 'records'
209
209
  a = self.xpath('//' + record_name)
@@ -214,43 +214,43 @@ class Polyrex
214
214
 
215
215
  make_dynarex doc.root
216
216
  end
217
-
217
+
218
218
  def records
219
219
 
220
- @doc.root.xpath("records/*").map do |node|
220
+ @doc.root.xpath("records/*").map do |node|
221
221
  Kernel.const_get(node.name.capitalize).new node, id: @id_counter
222
222
  end
223
-
223
+
224
224
  end
225
225
 
226
226
  def rxpath(s)
227
-
227
+
228
228
  a = @doc.root.xpath s.split('/').map \
229
229
  {|x| x.sub('[','[summary/').prepend('records/')}.join('/')
230
-
231
- a.map do |node|
230
+
231
+ a.map do |node|
232
232
  Kernel.const_get(node.name.capitalize).new node, id: node.attributes[:id]
233
233
  end
234
234
 
235
235
  end
236
-
236
+
237
237
  def schema=(s)
238
238
 
239
239
  if s =~ /gem\[/ then
240
- raise PolyrexException, "invalid schema: cannot contain the " +
240
+ raise PolyrexException, "invalid schema: cannot contain the " +
241
241
  "word gem as a record name"
242
242
  end
243
-
243
+
244
244
  openx(s)
245
245
 
246
246
  summary_h = Hash[*@doc.root.xpath("summary/*").\
247
247
  map {|x| [x.name, x.text.to_s]}.flatten]
248
248
 
249
249
  @summary = RecordX.new summary_h
250
- @summary_fields = summary_h.keys.map(&:to_sym)
250
+ @summary_fields = summary_h.keys.map(&:to_sym)
251
251
  self
252
252
  end
253
-
253
+
254
254
  def summary
255
255
  @summary
256
256
  end
@@ -258,7 +258,7 @@ class Polyrex
258
258
  def to_a()
259
259
  recordx_map @doc.root
260
260
  end
261
-
261
+
262
262
  def to_dynarex()
263
263
 
264
264
  root = @doc.root.deep_clone
@@ -267,17 +267,17 @@ class Polyrex
267
267
  #summary.delete('format_mask')
268
268
  #summary.element('recordx_type').text = 'dynarex'
269
269
 
270
- summary.add root.element('records/*/summary/format_mask').clone
270
+ summary.add root.element('records/*/summary/format_mask').clone
271
271
  e = summary.element('schema')
272
272
  e.text = e.text[/[^\/]+\/[^\/]+/].sub(/(\/\w+)\[([^\]]+)\]/,'\1(\2)')
273
273
 
274
274
  make_dynarex(root)
275
275
  end
276
-
276
+
277
277
  def to_opml()
278
-
278
+
279
279
  puts '@schema: ' + @schema.inspect if @debug
280
-
280
+
281
281
  head, body = @schema.split(/(?<=\])/,2)
282
282
  schema_body = body.gsub(/(?<=\[)[^\]]+/) do |x|
283
283
  x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
@@ -288,16 +288,16 @@ class Polyrex
288
288
 
289
289
  puts 'schema_body: ' + schema_body.inspect if @debug
290
290
  puts 'schema_head: ' + schema_head.inspect if @debug
291
- xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
291
+ xslt_schema = schema_head.sub(/^\w+/,'opml>head') +
292
292
  schema_body.gsub(/\w+(?=\[)/,'outline')\
293
293
  .sub(/\/(\w+)(?=\[)/,'/body>outline')
294
-
294
+
295
295
  puts 'xslt_schema: ' + xslt_schema.inspect if @debug
296
-
296
+
297
297
  recxslt = RecordxXSLT.new(schema: @schema, xslt_schema: xslt_schema)
298
-
299
- Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
300
-
298
+
299
+ Rexslt.new(recxslt.to_xslt, self.to_xml).to_s
300
+
301
301
  end
302
302
 
303
303
  def to_s(header: true)
@@ -312,9 +312,9 @@ class Polyrex
312
312
  puts 'line: ' + line.inspect if @debug
313
313
 
314
314
  recordsx = item.element('records').elements.to_a
315
-
315
+
316
316
  if recordsx.length > 0 then
317
- line = line + "\n" + build(recordsx, indent + 1).join("\n")
317
+ line = line + "\n" + build(recordsx, indent + 1).join("\n")
318
318
  end
319
319
  (' ' * indent) + line
320
320
  end
@@ -334,9 +334,9 @@ class Polyrex
334
334
  declaration = @raw_header
335
335
  else
336
336
 
337
- smry_fields = %i(schema)
337
+ smry_fields = %i(schema)
338
338
  if self.delimiter.length > 0 then
339
- smry_fields << :delimiter
339
+ smry_fields << :delimiter
340
340
  else
341
341
  smry_fields << :format_mask
342
342
  end
@@ -350,22 +350,22 @@ class Polyrex
350
350
  docheader = declaration + "\n" + sumry
351
351
  out = build(self.records).join("\n")
352
352
  header ? docheader + "\n" + out : out
353
-
353
+
354
354
  end
355
-
355
+
356
356
  def to_tree()
357
-
357
+
358
358
  s = @schema.gsub(/(?<=\[)[^\]]+/) do |x|
359
359
  x.split(/\s*,\s*/).map {|field| '@' + field + ':' + field}.join(', ')
360
360
  end
361
361
 
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
+ 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
367
365
 
368
- def to_xslt()
366
+ end
367
+
368
+ def to_xslt()
369
369
  @polyrex_xslt.schema = @schema
370
370
  @polyrex_xslt.to_xslt
371
371
  end
@@ -380,26 +380,26 @@ class Polyrex
380
380
  end
381
381
 
382
382
  def xslt=(value)
383
-
383
+
384
384
  @summary.xslt = value
385
385
 
386
- end
387
-
386
+ end
387
+
388
388
  def xslt_schema=(s)
389
389
  @polyrex_xslt.xslt_schema = s
390
390
  self
391
391
  end
392
-
392
+
393
393
  protected
394
-
394
+
395
395
  def doc()
396
396
  @doc
397
397
  end
398
398
 
399
399
  private
400
-
400
+
401
401
  def make_dynarex(root)
402
-
402
+
403
403
  root.delete('summary/recordx_type')
404
404
  root.delete('summary/format_mask')
405
405
  root.xpath('records/*/summary/format_mask').each(&:delete)
@@ -433,8 +433,8 @@ xsl_buffer = '
433
433
 
434
434
  buffer = Rexslt.new(xsl_buffer, root.xml).to_s
435
435
  Dynarex.new buffer
436
-
437
- end
436
+
437
+ end
438
438
 
439
439
  def refresh_records(records, fields, level)
440
440
 
@@ -469,10 +469,10 @@ xsl_buffer = '
469
469
  flatten.map(&:to_sym)
470
470
  summary = field_names.map {|x| "<%s/>" % x}.join
471
471
  end
472
-
472
+
473
473
  summary << "<recordx_type>polyrex</recordx_type><schema>#{schema}</schema>"
474
474
  #----
475
-
475
+
476
476
  @schema = schema
477
477
  @id_counter = '0'
478
478
 
@@ -481,12 +481,12 @@ xsl_buffer = '
481
481
  [root_name, (summary || '') , root_name])
482
482
 
483
483
  end
484
-
484
+
485
485
  def recordx_map(node)
486
-
486
+
487
487
  # get the summary
488
488
  fields = node.xpath('summary/*').map do |x|
489
- next if %w(schema format_mask recordx_type).include? x.name
489
+ next if %w(schema format_mask recordx_type).include? x.name
490
490
  r = x.text.to_s.gsub(/^[\n\s]+/,'').length > 0 ? x.text.to_s : \
491
491
  x.cdatas.join.strip
492
492
  r
@@ -494,28 +494,28 @@ xsl_buffer = '
494
494
 
495
495
  # get the records
496
496
  a = node.xpath('records/*').map {|x| recordx_map x}
497
-
497
+
498
498
  [fields.compact, a]
499
- end
500
-
499
+ end
500
+
501
501
  def string_parse(buffer, options={})
502
502
 
503
503
  @raw_header = buffer.slice!(/<\?polyrex[^>]+>/)
504
-
504
+
505
505
  if @raw_header then
506
506
  header = @raw_header[/<?polyrex (.*)?>/,1]
507
507
 
508
508
  r1 = /([\w\[\]\-]+\s*\=\s*'[^']*)'/
509
509
  r2 = /([\w\[\]\-]+\s*\=\s*"[^"]*)"/
510
510
 
511
- a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
511
+ a = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
512
+
512
513
 
513
-
514
514
  a.each do |x|
515
-
515
+
516
516
  attr, val = x.split(/\s*=\s*["']/,2)
517
517
 
518
- i = attr[/format_masks?\[(\d+)/,1]
518
+ i = attr[/format_masks?\[(\d+)/,1]
519
519
 
520
520
  if i then
521
521
 
@@ -527,16 +527,16 @@ xsl_buffer = '
527
527
  end
528
528
  end
529
529
  end
530
-
530
+
531
531
  options.each do |k,v|
532
-
532
+
533
533
  if options[k] then
534
534
  a.delete a.assoc(k)
535
535
  self.method(((k.to_s) + '=').to_sym).call(options[k])
536
536
  end
537
-
537
+
538
538
  end
539
-
539
+
540
540
  end
541
541
 
542
542
  raw_lines = buffer.lstrip.lines.map(&:chomp)
@@ -546,9 +546,9 @@ xsl_buffer = '
546
546
  if raw_summary then
547
547
  a_summary = raw_summary.split(',').map(&:strip)
548
548
 
549
- while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
549
+ while raw_lines.first[/#{a_summary.join('|')}:\s+\w+/] do
550
550
 
551
- label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
551
+ label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
552
552
  @summary.send((label + '=').to_sym, val)
553
553
  end
554
554
 
@@ -565,50 +565,50 @@ xsl_buffer = '
565
565
  puts 'lines: ' + lines.inspect if @debug
566
566
  @parent_node.root.add format_line!( lines)
567
567
 
568
- end
569
-
568
+ end
569
+
570
570
  def unescape(s)
571
571
  r = s.gsub('&lt;', '<').gsub('&gt;','>')
572
572
  end
573
-
573
+
574
574
  def load_handlers(schema)
575
575
 
576
- objects = PolyrexObjects.new(schema, debug: @debug)
576
+ objects = PolyrexObjects.new(schema, debug: @debug)
577
577
  h = objects.to_h
578
578
  puts 'h: ' + h.inspect if @debug
579
579
  @objects = h.inject({}){|r,x| r.merge x[0].downcase => x[-1]}
580
580
 
581
581
  @objects_a = objects.to_a
582
582
  attach_create_handlers(@objects.keys)
583
- #attach_edit_handlers(@objects)
583
+ #attach_edit_handlers(@objects)
584
584
 
585
585
  end
586
-
586
+
587
587
  def format_line!(a, i=0)
588
588
 
589
589
  records = Rexle::Element.new('records')
590
-
590
+
591
591
  # add code here for rowx
592
592
  @field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
593
593
  .flatten.map(&:to_sym)
594
594
 
595
595
  rowx_fields = a.map{|x| x.first[/^\w+(?=:)/].to_s.to_sym}.uniq
596
-
596
+
597
597
  records = if (@field_names & rowx_fields).length >= 2 then
598
598
  # rowx implementation still to-do
599
599
  #vertical_fiedlparse(records, a, i)
600
600
  else
601
601
  horizontal_fieldparse(records, a, i)
602
602
  end
603
-
603
+
604
604
  end
605
-
606
-
605
+
606
+
607
607
  # -- end of full text edit methods
608
-
608
+
609
609
  def horizontal_fieldparse(records, a, i)
610
610
 
611
- a.each do |x|
611
+ a.each do |x|
612
612
 
613
613
  unless @recordx[i] then
614
614
  @recordx[i] = @recordx[-1].clone
@@ -620,28 +620,28 @@ xsl_buffer = '
620
620
 
621
621
 
622
622
  line = raw_line
623
-
623
+
624
624
  if line[/\w+\s*---/] then
625
625
 
626
626
  node_name = line.sub(/\s*---/,'')
627
627
  ynode = Rexle::Element.new(node_name).add_text("---\n" + x.join("\n"))
628
-
628
+
629
629
  summary.add ynode
630
630
  next
631
631
  end
632
-
632
+
633
633
  puts '@schema: ' + @schema.inspect if @debug
634
634
  schema_a = @schema.split('/')[1..-1]
635
-
635
+
636
636
  if @debug then
637
637
  puts 'schema_a: ' + schema_a.inspect
638
638
  puts 'i: ' + i.inspect
639
639
  end
640
-
640
+
641
641
  unless @format_masks[i][/^\(.*\)$/] then
642
642
 
643
643
  @field_names, field_values = RXRawLineParser.new(format_masks[i])\
644
- .parse(line)
644
+ .parse(line)
645
645
 
646
646
  @field_names = schema_a[i] ? \
647
647
  schema_a[i][/\[([^\]]+)/,1].split(/\s*,\s*/).map(&:to_sym) : \
@@ -656,12 +656,12 @@ xsl_buffer = '
656
656
 
657
657
  pattern = patterns.detect {|x| line.match(/#{x}/)}
658
658
  i = patterns.index(pattern)
659
-
659
+
660
660
  @field_names = format_masks[i].to_s.scan(/\[!(\w+)\]/)\
661
661
  .flatten.map(&:to_sym)
662
662
 
663
- field_values = line.match(/#{pattern}/).captures
664
-
663
+ field_values = line.match(/#{pattern}/).captures
664
+
665
665
  end
666
666
 
667
667
  @id_counter.succ!
@@ -671,9 +671,9 @@ xsl_buffer = '
671
671
  record.add_attribute(id: @id_counter.clone)
672
672
  summary = Rexle::Element.new('summary')
673
673
 
674
- @field_names.zip(field_values).each do |name, value|
674
+ @field_names.zip(field_values).each do |name, value|
675
675
  field = Rexle::Element.new(name.to_s)
676
- field.text = value
676
+ field.text = value
677
677
  summary.add field
678
678
  end
679
679
 
@@ -685,42 +685,42 @@ xsl_buffer = '
685
685
  summary.add Rexle::Element.new('format_mask').add_text(format_mask)
686
686
  summary.add Rexle::Element.new('schema').add_text(schema)
687
687
  summary.add Rexle::Element.new('recordx_type').add_text('polyrex')
688
-
688
+
689
689
  record.add summary
690
690
  child_records = format_line!(x, i+1)
691
691
 
692
692
  record.add child_records
693
693
  records.add record
694
694
  end
695
-
695
+
696
696
  records
697
697
  end
698
698
 
699
699
  def attach_create_handlers(names)
700
700
  methodx = names.map do |name|
701
701
  %Q(
702
- def create_#{name.downcase}(params, &blk)
702
+ def create_#{name.downcase}(params, &blk)
703
703
  self.create.#{name.downcase}(params, &blk)
704
704
  end
705
705
  )
706
706
  end
707
707
 
708
708
  self.instance_eval(methodx.join("\n"))
709
-
709
+
710
710
  end
711
-
711
+
712
712
  def attach_edit_handlers(objects)
713
713
  objects.keys.each do |name|
714
714
  self.instance_eval(
715
715
  %Q(
716
- def #{name.downcase}()
716
+ def #{name.downcase}()
717
717
  @objects['#{name}'].new(@parent_node, id: @id)
718
718
  end
719
719
  ))
720
720
  end
721
-
721
+
722
722
  end
723
-
723
+
724
724
  def openx(s)
725
725
 
726
726
  if s[/</] # xml
@@ -728,7 +728,7 @@ xsl_buffer = '
728
728
  elsif s[/\[/] then # schema
729
729
  buffer = polyrex_new s
730
730
  elsif s[/^https?:\/\//] then # url
731
- buffer = open(s, 'UserAgent' => 'Polyrex-Reader').read
731
+ buffer = URI.open(s, 'UserAgent' => 'Polyrex-Reader').read
732
732
  else # local file
733
733
  buffer = File.read s
734
734
  @local_filepath = s
@@ -738,9 +738,9 @@ xsl_buffer = '
738
738
  @doc = Rexle.new buffer
739
739
 
740
740
  schema = @doc.root.text('summary/schema').to_s
741
-
741
+
742
742
  if schema.nil? then
743
- schema = PolyrexSchema.new.parse(buffer).to_schema
743
+ schema = PolyrexSchema.new.parse(buffer).to_schema
744
744
  e = @doc.root.element('summary')
745
745
  e.add Rexle::Element.new('schema').add_text(schema)
746
746
  end
@@ -763,7 +763,7 @@ xsl_buffer = '
763
763
  @parent_node = @doc.root.element('records')
764
764
 
765
765
  end
766
-
766
+
767
767
  def regexify_fmask(f)
768
768
 
769
769
  a = f.split(/(?=\[!\w+\])/).map do |x|
@@ -780,45 +780,45 @@ xsl_buffer = '
780
780
  end
781
781
  end
782
782
 
783
- a.join
783
+ a.join
784
784
  end
785
-
785
+
786
786
  def tail_map(a)
787
787
  [a] + (a.length > 1 ? tail_map(a[0..-2]) : [])
788
788
  end
789
-
789
+
790
790
 
791
791
  def load_find_by(schema)
792
792
 
793
793
  a = PolyrexObjectMethods.new(schema).to_a
794
794
 
795
- methodx = a.map do |class_name, methods|
796
-
795
+ methodx = a.map do |class_name, methods|
796
+
797
797
  class_name.downcase!
798
-
799
- methods.map do |method_name|
800
-
798
+
799
+ methods.map do |method_name|
800
+
801
801
  xpath = %Q(@doc.root.element("//%s[summary/%s='\#\{val\}']")) % \
802
802
  [class_name, method_name]
803
803
  xpath2 = %Q(@doc.root.xpath("//%s[summary/%s='\#\{val\}']")) % \
804
804
  [class_name, method_name]
805
-
806
- "def find_by_#{class_name}_#{method_name}(val)
807
-
805
+
806
+ "def find_by_#{class_name}_#{method_name}(val)
807
+
808
808
  node = #{xpath}
809
-
809
+
810
810
  if node then
811
811
  Kernel.const_get(node.name.capitalize).new node, id: @id
812
812
  else
813
813
  nil
814
814
  end
815
-
815
+
816
816
  end
817
817
 
818
- def find_all_by_#{class_name}_#{method_name}(val)
819
-
818
+ def find_all_by_#{class_name}_#{method_name}(val)
819
+
820
820
  nodes = #{xpath2}
821
-
821
+
822
822
  if nodes then
823
823
  nodes.map do |node|
824
824
  Kernel.const_get(node.name.capitalize).new node, id: @id
@@ -826,35 +826,35 @@ xsl_buffer = '
826
826
  else
827
827
  nil
828
828
  end
829
-
830
- end
829
+
830
+ end
831
831
  "
832
- end
832
+ end
833
833
  end
834
834
 
835
835
  self.instance_eval methodx.join("\n")
836
836
  end
837
837
 
838
838
 
839
- # refreshes the XML document with any new modification from
839
+ # refreshes the XML document with any new modification from
840
840
  # the summary object
841
841
  def refresh_summary()
842
-
843
- summary = @doc.root.element('summary')
842
+
843
+ summary = @doc.root.element('summary')
844
844
  @summary.to_h.each do |k,v|
845
-
845
+
846
846
  puts "k: %s; v: %s" % [k, v] if @debug
847
847
  e = summary.element(k.to_s)
848
848
  if e then
849
849
  e.text = v
850
850
  else
851
- summary.add Rexle::Element.new(k.to_s).add_text(v)
851
+ summary.add Rexle::Element.new(k.to_s).add_text(v)
852
852
  end
853
853
  end
854
-
854
+
855
855
  if @summary.xslt then
856
- @doc.instructions = [['xml-stylesheet',
857
- "title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
856
+ @doc.instructions = [['xml-stylesheet',
857
+ "title='XSL_formatting' type='text/xsl' href='#{@summary.xslt}'"]]
858
858
  end
859
859
  end
860
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.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  rivEdfkvT/8GV5Nip0lSS+cuk20UhOdJR9QIcCJp0QL4NUik9VYljGbQbQQS6Isc
36
36
  iIwZ6uFJfcp9SWBRrSZmlI52
37
37
  -----END CERTIFICATE-----
38
- date: 2021-06-05 00:00:00.000000000 Z
38
+ date: 2021-11-18 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.1
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.1
59
+ version: 1.0.3
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: polyrex-object-methods
62
62
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  version: '1.8'
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 1.8.19
109
+ version: 1.8.27
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
@@ -116,9 +116,9 @@ dependencies:
116
116
  version: '1.8'
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 1.8.19
119
+ version: 1.8.27
120
120
  description:
121
- email: james@jamesrobertson.eu
121
+ email: digital.robertson@gmail.com
122
122
  executables: []
123
123
  extensions: []
124
124
  extra_rdoc_files: []
@@ -143,7 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.1.2
146
+ rubyforge_project:
147
+ rubygems_version: 2.7.10
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: A flavour of XML for storing and retrieveing records in a Polyrex hierarchy
metadata.gz.sig CHANGED
Binary file