dynarex 1.0.26 → 1.0.27

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 +26 -29
  2. metadata +2 -2
@@ -8,6 +8,7 @@ require 'ostruct'
8
8
  require 'dynarex-import'
9
9
  require 'line-tree'
10
10
  require 'rexle'
11
+ require 'rexlebuilder'
11
12
 
12
13
  class Dynarex
13
14
 
@@ -101,13 +102,6 @@ EOF
101
102
 
102
103
  #format_mask = XPath.first(@doc.root, 'summary/format_mask/text()').to_s
103
104
  format_mask = @doc.element('summary/format_mask/text()')
104
- dynarex = Dynarex.new
105
-
106
- s = %q(schema="companies/company(name, last_contacted, contact)" delimiter=" # ")
107
- s.split(/(?=\w+\="[^"]+")/)
108
- raw_a = s.scan(/\w+\="[^"]+"/)
109
- a = raw_a.map{|x| r = x.split(/=/); [(r[0] + "=").to_sym, r[1][/^"(.*)"$/,1]] }
110
- a.each{|name, value| dynarex.method(name).call(value)}
111
105
 
112
106
  xslt_format = format_mask.to_s.gsub(/\s(?=\[!\w+\])/,'<xsl:text> </xsl:text>').gsub(/\[!(\w+)\]/, '<xsl:value-of select="\1"/>')
113
107
  xsl_buffer.sub!(/\[!regex_values\]/, xslt_format)
@@ -251,7 +245,9 @@ EOF
251
245
  OpenStruct.new(Hash[*@fields.zip(recordx.xpath("*/text()")).flatten])
252
246
  end
253
247
 
254
- def hash_create(params={}, id=nil)
248
+ def hash_create(raw_params={}, id=nil)
249
+
250
+ params = Hash[raw_params.keys.map(&:to_sym).zip(raw_params.values)]
255
251
 
256
252
  fields = capture_fields(params)
257
253
  record = Rexle::Element.new @record_name
@@ -261,8 +257,9 @@ EOF
261
257
  record.add element
262
258
  end
263
259
 
264
- id = (@doc.xpath('max(records/*/attribute::id)').to_i + 1).to_s unless id
265
260
 
261
+ id = (@doc.xpath('max(records/*/attribute::id)') || '0').succ unless id
262
+
266
263
  attributes = {id: id, created: Time.now.to_s, last_modified: nil}
267
264
  attributes.each {|k,v| record.add_attribute(k, v)}
268
265
 
@@ -272,39 +269,39 @@ EOF
272
269
 
273
270
  def capture_fields(params)
274
271
  fields = Hash[@fields.map {|x| [x,nil]}]
275
- fields.keys.each {|key| fields[key] = params[key] if params.has_key? key}
272
+ fields.keys.each {|key| fields[key] = params[key.to_sym] if params.has_key? key.to_sym}
276
273
  fields
277
274
  end
278
275
 
279
276
 
280
277
  def display_xml
281
278
  rebuild_doc()
282
- @doc.xml pretty: true
279
+ @doc.xml #jr230711 pretty: true
283
280
  end
284
281
 
285
282
  def rebuild_doc
286
-
287
- builder = Nokogiri::XML::Builder.new do |xml|
288
- xml.send @root_name do
289
- xml.summary do
290
- @summary.each{|key,value| xml.send key, value}
291
- end
292
- if @records then
293
- xml.records do
294
-
295
- @records.each do |k, item|
296
- xml.send(@record_name, id: item[:id], created: item[:created], \
297
- last_modified: item[:last_modified]) do
298
- item[:body].each{|name,value| xml.send name, value}
299
- end
300
- end
301
283
 
302
- end
303
- end # end of if @records
284
+ xml = RexleBuilder.new
285
+ a = xml.send @root_name do
286
+ xml.summary do
287
+ @summary.each{|key,value| xml.send key, value}
304
288
  end
289
+ if @records then
290
+ xml.records do
291
+
292
+ @records.each do |k, item|
293
+ p 'foo ' + item.inspect
294
+ xml.send(@record_name, {id: item[:id], created: item[:created], \
295
+ last_modified: item[:last_modified]}, '') do
296
+ item[:body].each{|name,value| xml.send name, value}
297
+ end
298
+ end
299
+
300
+ end
301
+ end # end of if @records
305
302
  end
306
303
 
307
- @doc = Rexle.new builder.to_xml
304
+ @doc = Rexle.new a
308
305
 
309
306
  end
310
307
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynarex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.26
5
+ version: 1.0.27
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: 2011-07-23 00:00:00 +01:00
13
+ date: 2011-07-24 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency