dynarex 1.1.21 → 1.1.22

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.rb +12 -22
  2. metadata +2 -2
@@ -3,7 +3,6 @@
3
3
  # file: dynarex.rb
4
4
 
5
5
  require 'open-uri'
6
- require 'ostruct'
7
6
  require 'dynarex-import'
8
7
  require 'line-tree'
9
8
  require 'rexle'
@@ -11,6 +10,7 @@ require 'rexle-builder'
11
10
  require 'rexslt'
12
11
  require 'dynarex-xslt'
13
12
  require 'recordx'
13
+ require 'rxraw-lineparser'
14
14
 
15
15
  class Dynarex
16
16
 
@@ -59,7 +59,7 @@ class Dynarex
59
59
  @summary[:format_mask] = @format_mask
60
60
  end
61
61
 
62
- def inspect2()
62
+ def inspect()
63
63
  "<object #%s>" % [self.object_id]
64
64
  end
65
65
 
@@ -191,7 +191,6 @@ EOF
191
191
 
192
192
  end
193
193
 
194
-
195
194
 
196
195
  #Delete a record.
197
196
  # dyarex.delete 3 # deletes record with id 3
@@ -305,8 +304,7 @@ EOF
305
304
  end
306
305
 
307
306
  def recordx_to_record(recordx)
308
- RecordX.new(self, recordx.attributes[:id], \
309
- Hash[*@fields.zip(recordx.xpath("*/text()")).flatten])
307
+ RecordX.new(Hash[*@fields.zip(recordx.xpath("*/text()")).flatten], self, recordx.attributes[:id])
310
308
  end
311
309
 
312
310
  def hash_create(raw_params={}, id=nil)
@@ -323,12 +321,7 @@ EOF
323
321
  record.add element if record
324
322
  end
325
323
 
326
- #jr250811 puts 'id : ' + @doc.root.xpath("max(records/*/attribute::id)").inspect
327
- #jr250811 puts '@doc ' + @doc.xml
328
- #jr250811 puts 'company ' + @doc.root.xpath("records/company/@id").inspect
329
- #jr250811 puts
330
324
  id = (@doc.root.xpath('max(records/*/attribute::id)') || '0').succ unless id
331
- #jr250811 puts 'id2 : ' + id.inspect
332
325
 
333
326
  attributes = {id: id, created: Time.now.to_s, last_modified: nil}
334
327
  attributes.each {|k,v| record.add_attribute(k, v)}
@@ -341,7 +334,6 @@ EOF
341
334
  fields.keys.each {|key| fields[key] = params[key.to_sym] if params.has_key? key.to_sym}
342
335
  fields
343
336
  end
344
-
345
337
 
346
338
  def display_xml(opt={})
347
339
  rebuild_doc()
@@ -366,7 +358,7 @@ EOF
366
358
  # 'a' and 'a_split' just used for validation
367
359
  a = @format_mask.scan(/\[!\w+\]/)
368
360
  a_split = @format_mask.split(/\[!\w+\]/)
369
-
361
+
370
362
  if a.length == 2 and a_split[1].length == 1 then
371
363
  t = "([^#{a_split[1]}]+)" + a_split[1] + "(.*)"
372
364
  else
@@ -390,8 +382,11 @@ EOF
390
382
  @summary[:recordx_type] = 'dynarex'
391
383
  @summary[:schema] = @schema
392
384
  @summary[:format_mask] = @format_mask
393
-
394
- lines = raw_lines.map {|x|x.strip.match(/#{t}/).captures}
385
+
386
+ lines = raw_lines.map do |x|
387
+ field_names, field_values = RXRawLineParser.new(@format_mask).parse(x)
388
+ field_values
389
+ end
395
390
 
396
391
  a = lines.map do|x|
397
392
  created = Time.now.to_s
@@ -399,7 +394,7 @@ EOF
399
394
  h = Hash[@fields.zip(x)]
400
395
  [h[@default_key], {id: '', created: created, last_modified: '', body: h}]
401
396
  end
402
-
397
+
403
398
  h2 = Hash[a]
404
399
 
405
400
  #replace the existing records hash
@@ -418,7 +413,7 @@ EOF
418
413
  h[key] = item.clone
419
414
  end
420
415
  end
421
-
416
+
422
417
  h.each {|key, item| h.delete(key) if not h2.has_key? key}
423
418
  #refresh_doc
424
419
  #load_records
@@ -446,7 +441,6 @@ EOF
446
441
 
447
442
  end
448
443
 
449
-
450
444
  format_mask = fields ? fields.map {|x| "[!%s]" % x}.join(' ') : ''
451
445
 
452
446
  @summary = Hash[summary.zip([''] * summary.length).flatten.each_slice(2)\
@@ -464,7 +458,6 @@ EOF
464
458
  end
465
459
 
466
460
  def open(s)
467
-
468
461
 
469
462
  if s[/</] then # xml
470
463
  buffer = s
@@ -477,9 +470,6 @@ EOF
477
470
  buffer = File.open(s,'r').read
478
471
  end
479
472
 
480
-
481
- #@doc = Rexle.new buffer
482
-
483
473
  @doc = Rexle.new(buffer) unless @doc
484
474
 
485
475
  @schema = @doc.root.text('summary/schema')
@@ -503,7 +493,7 @@ EOF
503
493
  else
504
494
  @default_key = @doc.root.xpath('records/*/*').first.name
505
495
  end
506
-
496
+
507
497
  if @doc.root.xpath('records/*').length > 0 then
508
498
  @record_name = @doc.root.element('records/*[1]').name
509
499
  load_records
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynarex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.21
5
+ version: 1.1.22
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-04-17 00:00:00 +01:00
13
+ date: 2012-04-26 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency