dynarex 1.1.34 → 1.1.35
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.
- data/lib/dynarex.rb +38 -9
- metadata +2 -2
data/lib/dynarex.rb
CHANGED
@@ -11,6 +11,7 @@ require 'rexslt'
|
|
11
11
|
require 'dynarex-xslt'
|
12
12
|
require 'recordx'
|
13
13
|
require 'rxraw-lineparser'
|
14
|
+
require 'yaml'
|
14
15
|
|
15
16
|
class Dynarex
|
16
17
|
|
@@ -26,9 +27,11 @@ class Dynarex
|
|
26
27
|
# Dynarex.new '<contacts><summary><schema>contacts/contact(name,age,dob)</schema></summary><records/></contacts>'
|
27
28
|
|
28
29
|
def initialize(location=nil)
|
30
|
+
|
29
31
|
@delimiter = ' '
|
30
32
|
open(location) if location
|
31
33
|
@dirty_flag = false
|
34
|
+
@logger = Logger.new('/tmp/dynarex.log','daily')
|
32
35
|
end
|
33
36
|
|
34
37
|
def add(x)
|
@@ -252,7 +255,7 @@ EOF
|
|
252
255
|
item[:body].each do |name,value|
|
253
256
|
#name = name.to_s.prepend('._').to_sym if reserved_keywords.include? name
|
254
257
|
name = ('._' + name.to_s).to_sym if reserved_keywords.include? name
|
255
|
-
xml.send name, value
|
258
|
+
xml.send name, value.to_s
|
256
259
|
end
|
257
260
|
end
|
258
261
|
end
|
@@ -262,7 +265,7 @@ EOF
|
|
262
265
|
xml.records
|
263
266
|
end # end of if @records
|
264
267
|
end
|
265
|
-
|
268
|
+
|
266
269
|
@doc = Rexle.new a
|
267
270
|
end
|
268
271
|
|
@@ -276,7 +279,9 @@ EOF
|
|
276
279
|
|
277
280
|
def to_xslt(opt={})
|
278
281
|
h = {limit: -1}.merge(opt)
|
282
|
+
@logger.debug "@schema: %s; @xslt_schema: %s" % [@schema, @xslt_schema]
|
279
283
|
xslt = DynarexXSLT.new(schema: @schema, xslt_schema: @xslt_schema).to_xslt
|
284
|
+
@logger.debug 'xslt : ' + xslt.inspect
|
280
285
|
return xslt
|
281
286
|
end
|
282
287
|
|
@@ -309,7 +314,7 @@ EOF
|
|
309
314
|
doc.root.xpath('records/*').each do |x|
|
310
315
|
raw_dt = DateTime.parse x.attributes[:created]
|
311
316
|
dt = raw_dt.strftime("%a, %d %b %Y %H:%M:%S %z")
|
312
|
-
x.add Rexle::Element.new('pubDate').add_text dt
|
317
|
+
x.add Rexle::Element.new('pubDate').add_text dt.to_s
|
313
318
|
end
|
314
319
|
|
315
320
|
xml = Rexslt.new(xslt, doc.xml).to_s
|
@@ -414,15 +419,37 @@ EOF
|
|
414
419
|
@summary[:schema] = @schema
|
415
420
|
@summary[:format_mask] = @format_mask
|
416
421
|
|
417
|
-
|
418
|
-
|
419
|
-
|
422
|
+
if raw_lines.first == '---' then
|
423
|
+
|
424
|
+
yaml = YAML.load raw_lines.join("\n")
|
425
|
+
|
426
|
+
yamlize = lambda {|x| (x.is_a? Array) ? '--- ' + x.to_s : x}
|
427
|
+
|
428
|
+
yprocs = {
|
429
|
+
Hash: lambda {|y|
|
430
|
+
y.map do |k,v|
|
431
|
+
procs = {Hash: proc {|x| x.values}, Array: proc {v}}
|
432
|
+
values = procs[v.class.to_s.to_sym].call(v).map(&yamlize)
|
433
|
+
[k, *values]
|
434
|
+
end
|
435
|
+
},
|
436
|
+
Array: lambda {|y| y.map {|x2| x2.map(&yamlize)} }
|
437
|
+
}
|
438
|
+
|
439
|
+
lines = yprocs[yaml.class.to_s.to_sym].call yaml
|
440
|
+
else
|
441
|
+
|
442
|
+
lines = raw_lines.map do |x|
|
443
|
+
field_names, field_values = RXRawLineParser.new(@format_mask).parse(x)
|
444
|
+
field_values
|
445
|
+
end
|
446
|
+
|
420
447
|
end
|
421
448
|
|
422
449
|
a = lines.map do|x|
|
423
450
|
created = Time.now.to_s
|
424
451
|
|
425
|
-
h = Hash[@fields.zip(x)]
|
452
|
+
h = Hash[@fields.zip(x.map{|t| t.to_s[/^--- /] ? YAML.load(t) : t})]
|
426
453
|
[h[@default_key], {id: '', created: created, last_modified: '', body: h}]
|
427
454
|
end
|
428
455
|
|
@@ -532,6 +559,7 @@ EOF
|
|
532
559
|
end
|
533
560
|
|
534
561
|
def load_records
|
562
|
+
|
535
563
|
@records = records_to_h
|
536
564
|
@records.instance_eval do
|
537
565
|
def delete_item(i)
|
@@ -556,7 +584,7 @@ EOF
|
|
556
584
|
|
557
585
|
created = Time.now.to_s
|
558
586
|
last_modified = ''
|
559
|
-
|
587
|
+
|
560
588
|
if row.attributes[:id] then
|
561
589
|
id = row.attributes[:id]
|
562
590
|
else
|
@@ -566,7 +594,8 @@ EOF
|
|
566
594
|
created = row.attributes[:created] if row.attributes[:created]
|
567
595
|
last_modified = row.attributes[:last_modified] if row.attributes[:last_modified]
|
568
596
|
body = row.xpath('*').inject({}) do |r,node|
|
569
|
-
|
597
|
+
text = node.text.unescape
|
598
|
+
r.merge node.name.to_sym => (text[/^--- /] ? YAML.load(text) : text)
|
570
599
|
end
|
571
600
|
|
572
601
|
result.merge body[@default_key.to_sym] => {id: id, created: created, last_modified: last_modified, body: body}
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dynarex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.35
|
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-07-
|
13
|
+
date: 2012-07-27 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rexle
|