dynarex 0.4.0 → 0.4.1

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 +17 -6
  2. metadata +2 -2
@@ -56,13 +56,15 @@ EOF
56
56
  end
57
57
 
58
58
  def parse(buffer)
59
+ i = XPath.match(@doc.root, 'records/*/attribute::id').max_by(&:value).to_s.to_i
59
60
  format_mask = XPath.first(@doc.root, 'summary/format_mask/text()').to_s
60
61
  t = format_mask.to_s.gsub(/\[!(\w+)\]/, '(.*)').sub(/\[/,'\[').sub(/\]/,'\]')
61
62
  lines = buffer.split(/\r?\n|\r(?!\n)/).map {|x|x.match(/#{t}/).captures}
62
63
  fields = format_mask.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
63
64
 
64
- a = lines.each_with_index.map do|x,i|
65
- created = Time.now.to_s; id = Time.now.strftime("%Y%m%I%H%M%S") + i.to_s
65
+ a = lines.map do|x|
66
+ created = Time.now.to_s
67
+
66
68
  h = Hash[fields.zip(x)]
67
69
  [h[@default_key], {id: id, created: created, last_modified: '', body: h}]
68
70
  end
@@ -80,7 +82,8 @@ EOF
80
82
  h[key][:body][k.to_sym] = v
81
83
  end
82
84
  else
83
-
85
+ i += 1
86
+ item[:id] = i.to_s
84
87
  h[key] = item.clone
85
88
  end
86
89
  end
@@ -137,10 +140,18 @@ EOF
137
140
  end
138
141
 
139
142
  def records_to_h()
140
- ah = XPath.match(@doc.root, 'records/*').each_with_index.map do |row,i|
141
- created = Time.now.to_s; id = Time.now.strftime("%Y%m%I%H%M%S") + i.to_s
143
+ i = XPath.match(@doc.root, 'records/*/attribute::id').max_by(&:value).to_s.to_i
144
+
145
+ ah = XPath.match(@doc.root, 'records/*').map do |row|
146
+
147
+ created = Time.now.to_s
142
148
  last_modified = ''
143
- id = row.attribute('id').value.to_s if row.attribute('id')
149
+
150
+ if row.attribute('id') then
151
+ id = row.attribute('id').value.to_s
152
+ else
153
+ i += 1; id = i.to_s
154
+ end
144
155
  created = row.attribute('created').value.to_s if row.attribute('created')
145
156
  last_modified = row.attribute('last_modified').value.to_s if row.attribute('last_modified')
146
157
  body = XPath.match(row, '*').inject({}) do |r,node|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynarex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-07 00:00:00 +01:00
12
+ date: 2010-04-08 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15