dynarex 1.1.38 → 1.1.39
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dynarex.rb +20 -6
- metadata +2 -2
data/lib/dynarex.rb
CHANGED
@@ -15,7 +15,7 @@ require 'yaml'
|
|
15
15
|
|
16
16
|
class Dynarex
|
17
17
|
|
18
|
-
attr_accessor :format_mask, :delimiter, :xslt_schema, :schema
|
18
|
+
attr_accessor :format_mask, :delimiter, :xslt_schema, :schema, :order
|
19
19
|
|
20
20
|
|
21
21
|
#Create a new dynarex document from 1 of the following options:
|
@@ -365,7 +365,18 @@ EOF
|
|
365
365
|
|
366
366
|
attributes = {id: id, created: Time.now.to_s, last_modified: nil}
|
367
367
|
attributes.each {|k,v| record.add_attribute(k, v)}
|
368
|
-
@
|
368
|
+
if @order == 'descending' then
|
369
|
+
|
370
|
+
element = @doc.root.element('records/.[1]')
|
371
|
+
if element then
|
372
|
+
element.insert_before record
|
373
|
+
else
|
374
|
+
@doc.root.element('records').add record
|
375
|
+
end
|
376
|
+
|
377
|
+
else
|
378
|
+
@doc.root.element('records').add record
|
379
|
+
end
|
369
380
|
|
370
381
|
end
|
371
382
|
|
@@ -376,6 +387,7 @@ EOF
|
|
376
387
|
end
|
377
388
|
|
378
389
|
def display_xml(opt={})
|
390
|
+
|
379
391
|
load_records if @dirty_flag == true
|
380
392
|
rebuild_doc()
|
381
393
|
@doc.xml(opt) #jr230711 pretty: true
|
@@ -401,6 +413,7 @@ EOF
|
|
401
413
|
raw_summary = schema[/\[([^\]]+)/,1]
|
402
414
|
raw_lines = buffer.gsub(/^\s*#[^\n]+/,'').gsub(/\n\n/,"\n")\
|
403
415
|
.strip.split(/\r?\n|\r(?!\n)/)
|
416
|
+
raw_lines.reverse! if @order == 'descending'
|
404
417
|
|
405
418
|
if raw_summary then
|
406
419
|
a_summary = raw_summary.split(',').map(&:strip)
|
@@ -455,6 +468,7 @@ EOF
|
|
455
468
|
|
456
469
|
#replace the existing records hash
|
457
470
|
h = @records
|
471
|
+
i = 0
|
458
472
|
h2.each do |key,item|
|
459
473
|
if h.has_key? key then
|
460
474
|
|
@@ -463,9 +477,9 @@ EOF
|
|
463
477
|
item[:body].each do |k,v|
|
464
478
|
h[key][:body][k.to_sym] = v
|
465
479
|
end
|
466
|
-
else
|
480
|
+
else
|
481
|
+
item[:id] = (@order == 'descending' ? (h2.count) - i : i+ 1).to_s
|
467
482
|
i += 1
|
468
|
-
item[:id] = i.to_s
|
469
483
|
h[key] = item.clone
|
470
484
|
end
|
471
485
|
end
|
@@ -577,7 +591,7 @@ EOF
|
|
577
591
|
def records_to_h()
|
578
592
|
|
579
593
|
i = @doc.root.xpath('max(records/*/attribute::id)') || 0
|
580
|
-
|
594
|
+
|
581
595
|
@doc.root.xpath('records/*').inject({}) do |result,row|
|
582
596
|
|
583
597
|
created = Time.now.to_s
|
@@ -608,4 +622,4 @@ EOF
|
|
608
622
|
end
|
609
623
|
end
|
610
624
|
|
611
|
-
end
|
625
|
+
end
|
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.39
|
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-
|
13
|
+
date: 2012-08-11 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rexle
|