dynarex 1.0.22 → 1.0.24

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 +18 -22
  2. metadata +2 -2
@@ -156,7 +156,7 @@ EOF
156
156
  # dynarex.create_from_line 'Tracy 37 15-Jun-1972'
157
157
 
158
158
  def create_from_line(line, id=nil)
159
- t = regexify_fmask(@format_mask)
159
+ t = @format_mask.to_s.gsub(/\[!(\w+)\]/, '(.*)').sub(/\[/,'\[').sub(/\]/,'\]')
160
160
  line.match(/#{t}/).captures
161
161
 
162
162
  a = line.match(/#{t}/).captures
@@ -319,8 +319,18 @@ EOF
319
319
 
320
320
  # if records already exist find the max id
321
321
  i = @doc.xpath('max(records/*/attribute::id)').to_i
322
+
323
+
324
+ # 'a' and 'a_split' just used for validation
325
+ a = @format_mask.scan(/\[!\w+\]/)
326
+ a_split = @format_mask.split(/\[!\w+\]/)
322
327
 
323
- t = regexify_fmask(@format_mask)
328
+ if a.length == 2 and a_split[1].length == 1 then
329
+ t = "([^#{a_split[1]}]+)" + a_split[1] + "(.*)"
330
+ else
331
+ # convert the format mask into a friendly reg exp string
332
+ t = @format_mask.to_s.gsub(/\[!(\w+)\]/, '(.*)').sub(/\[/,'\[').sub(/\]/,'\]')
333
+ end
324
334
 
325
335
  lines = buffer.strip.split(/\r?\n|\r(?!\n)/).map {|x|x.strip.match(/#{t}/).captures}
326
336
 
@@ -431,7 +441,12 @@ LINES
431
441
 
432
442
  def load_records
433
443
  @records = records_to_h
434
-
444
+ @records.instance_eval do
445
+ def delete_item(i)
446
+ self.delete self.keys[i]
447
+ end
448
+ end
449
+
435
450
  #Returns a ready-only snapshot of records as a simple Hash.
436
451
  @flat_records = @records.values.map{|x| x[:body]}
437
452
  end
@@ -465,25 +480,6 @@ LINES
465
480
  end
466
481
 
467
482
  end
468
-
469
- def regexify_fmask(f)
470
-
471
- a = f.split(/(?=\[!\w+\])/).map do |x|
472
-
473
- aa = x.split(/(?=[^\]]+$)/)
474
-
475
- if aa.length == 2 and aa.first[/\[!\w+\]/] then
476
- field, delimiter = *aa
477
- delimiter ||= '$'
478
- d = delimiter[0]
479
- "([^%s]+)%s" % ([d] * 2)
480
- else
481
- x.sub(/\[!\w+\]/,'(.*)')
482
- end
483
- end
484
-
485
- a.join
486
- end
487
483
 
488
484
  def summary_to_h
489
485
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynarex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.22
5
+ version: 1.0.24
6
6
  platform: ruby
7
7
  authors: []
8
8
 
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-17 00:00:00 +00:00
13
+ date: 2011-04-27 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency