dynarex 1.2.14 → 1.2.15

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.
Files changed (2) hide show
  1. data/lib/dynarex.rb +22 -5
  2. metadata +2 -2
@@ -18,7 +18,7 @@ class Dynarex
18
18
 
19
19
  attr_accessor :format_mask, :delimiter, :xslt_schema, :schema, :order, :type
20
20
 
21
- def self.gem_url() 'http://www.jamesrobertson.eu/ruby/dynarex#1.2.14' end
21
+ def self.gem_url() 'http://www.jamesrobertson.eu/ruby/dynarex#1.2.15' end
22
22
 
23
23
  #Create a new dynarex document from 1 of the following options:
24
24
  #* a local file path
@@ -84,8 +84,9 @@ class Dynarex
84
84
  end
85
85
 
86
86
  def type=(v)
87
- @order = 'descending' if v = 'feed'
87
+ @order = 'descending' if v == 'feed'
88
88
  @type = v
89
+ @summary[:type] = v
89
90
  end
90
91
 
91
92
  # Returns the hash representation of the document summary.
@@ -425,7 +426,7 @@ EOF
425
426
  header.scan(/\w+\s*=\s*(?:"[^"]+"|'[^']+')/).map\
426
427
  {|x| r = x.split(/=/,2); [(r[0].rstrip + "=").to_sym, \
427
428
  r[1][/^\s*"(.*)"$/,1]] }.each \
428
- {|name, value| self.method(name).call(value)}
429
+ {|name, value| self.method(name).call(value)}
429
430
  end
430
431
 
431
432
  # if records already exist find the max id
@@ -444,12 +445,26 @@ EOF
444
445
 
445
446
  @summary = {}
446
447
 
448
+ # fetch any summary lines
447
449
  while not raw_lines.empty? and \
448
450
  raw_lines.first[/#{a_summary.join('|')}:\s+[\w\*\-\+]+/] do
449
451
  label, val = raw_lines.shift.match(/(\w+):\s+([^$]+)$/).captures
450
452
  @summary[label] = val
451
453
  end
452
454
  end
455
+
456
+ if @type == 'checklist' then
457
+
458
+ # extract the brackets from the line
459
+
460
+ checked = []
461
+ raw_lines.map! do |x|
462
+ raw_checked, raw_line = x.partition(/\]/).values_at 0,2
463
+ checked << (raw_checked[/x/] ? true : false)
464
+ raw_line
465
+ end
466
+
467
+ end
453
468
 
454
469
  if @order == 'descending' then
455
470
  rl = raw_lines
@@ -461,6 +476,7 @@ EOF
461
476
  raw_lines = rl.each_slice(@fields.count).inject([])\
462
477
  {|r,x| r += x.reverse }.reverse
463
478
  end
479
+ checked.reverse! if @type == 'checklist'
464
480
 
465
481
  end
466
482
 
@@ -498,7 +514,7 @@ EOF
498
514
  else
499
515
 
500
516
  raw_lines.map.with_index do |x,i|
501
-
517
+
502
518
  begin
503
519
  field_names, field_values = RXRawLineParser.new(@format_mask).parse(x)
504
520
  rescue
@@ -509,9 +525,10 @@ EOF
509
525
 
510
526
  end
511
527
 
512
- a = lines.map do|x|
528
+ a = lines.map.with_index do |x,i|
513
529
  created = Time.now.to_s
514
530
  h = Hash[@fields.zip(x.map{|t| t.to_s[/^---/] ? YAML.load(t) : t})]
531
+ h[@fields.last] = checked[i].to_s if @type == 'checklist'
515
532
  [h[@default_key], {id: '', created: created, last_modified: '', body: h}]
516
533
  end
517
534
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynarex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.14
5
+ version: 1.2.15
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: 2013-01-07 00:00:00 Z
13
+ date: 2013-01-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rexle