dynarex 1.4.1 → 1.5.0

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 (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/dynarex.rb +97 -66
  5. metadata +27 -67
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa8b7da4e8d5cd1b23e6bce5d1d852b4abe26fed
4
- data.tar.gz: b1b2b7004882805809d372c78b610cce6cc5ce13
3
+ metadata.gz: 1b84b89265aa1ec7adf68b5a5b044a6ce0e13d1d
4
+ data.tar.gz: aba66ad0418ac4ee49243a4adaf466c2da0b2021
5
5
  SHA512:
6
- metadata.gz: 957ba23b15ccef7e0c08bc78c7dfb2f22e769c8250c0b0b665ba1ee7c256e881f1f6774fa76be6d67f23380a0ec830a8f40829f8a7beb78811750c6875aa908e
7
- data.tar.gz: a538cfac322d0bb91e679e2b2023d189ecb5d04e363e73f91a7735e24b444fbb0a84d385913fc3084587a3186cb08ca81ce759768ccad58df9197ea289388998
6
+ metadata.gz: 02c7dc48abe83da86fd2a17ca13870ca4792a599347952c8852e0bcc2c179d722c9da823a03fc38c76e445f2019ebd86a13e4be2fa9184840f99e0c662e51f1d
7
+ data.tar.gz: 1453ab33d8666f11167f63b6c8e6dfb7dfc4d0019daa63be36404b5cfb2977e27aafc37ee4178ca17c2865aa4bedf2073f20a8d6aee0a42ee516694ac4e7a5bc
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,8 +4,8 @@
4
4
 
5
5
  require 'open-uri'
6
6
  require 'dynarex-import'
7
- require 'line-tree'
8
- require 'rexle'
7
+ #require 'line-tree'
8
+ #require 'rexle'
9
9
  require 'rexle-builder'
10
10
  require 'rexslt'
11
11
  require 'dynarex-xslt'
@@ -39,6 +39,7 @@ class Dynarex
39
39
 
40
40
  def initialize(rawx=nil, opt={})
41
41
 
42
+ #@log = Logger.new('/home/james/mm.log')
42
43
  @opt = {username: nil, password: nil}.merge opt
43
44
  @delimiter = ''
44
45
 
@@ -286,12 +287,14 @@ EOF
286
287
  #Parses 1 or more lines of text to create or update existing records.
287
288
 
288
289
  def parse(x=nil)
289
-
290
+ #log = Logger.new('/home/james/mm.log')
291
+ #log.debug('dynarex: inside parse()')
290
292
  raw_buffer, type = RXFHelper.read(x)
291
293
 
292
294
  if raw_buffer.is_a? String then
293
295
  buffer = raw_buffer.clone
294
296
  buffer = yield if block_given?
297
+ #log.debug('dynarex: before string_parse()')
295
298
  string_parse buffer
296
299
  else
297
300
  foreign_import x
@@ -446,13 +449,17 @@ EOF
446
449
  end # end of if @records
447
450
  end
448
451
 
452
+ #@log.debug('dynarex: a = ' + a.inspect)
449
453
  doc = Rexle.new(a)
450
454
 
455
+ #@log.debug('dynarex: doc.inspect : ' + doc.inspect)
456
+ #@log.debug('dynarex: doc ' + doc.xml[0..149].inspect)
451
457
  if @xslt then
452
458
  doc.instructions = [['xml-stylesheet',
453
459
  "title='XSL_formatting' type='text/xsl' href='#{@xslt}'"]]
454
460
  end
455
461
 
462
+ #log.debug('dynarex: state: ' + state.inspect)
456
463
  return doc if state != :internal
457
464
  @doc = doc
458
465
  end
@@ -628,7 +635,7 @@ EOF
628
635
  alias refresh_doc display_xml
629
636
 
630
637
  def string_parse(buffer)
631
-
638
+ #@log.debug '+string_parse'
632
639
  buffer.gsub!("\r",'')
633
640
  buffer.gsub!(/\n-{4,}\n/,"\n\n")
634
641
  buffer.gsub!(/---\n/m, "--- ")
@@ -637,30 +644,37 @@ EOF
637
644
  buffer.gsub!(/<./) {|x| x[1] != '?' ? x.sub(/</,'&lt;') : x }
638
645
 
639
646
  @raw_header = buffer[/<\?dynarex[^>]+>/]
640
-
647
+ #log = Logger.new('/home/james/mm.log')
648
+ #log.debug('dynarex: before if buffer()')
649
+ #@log.debug 'before buffer match'
650
+
641
651
  if buffer[/<\?/] then
642
-
652
+ #@log.debug 'inside buffer'
643
653
  raw_stylesheet = buffer.slice!(/<\?xml-stylesheet[^>]+>/)
644
654
  @xslt = raw_stylesheet[/href=["']([^"']+)/,1] if raw_stylesheet
645
655
  @raw_header = buffer.slice!(/<\?dynarex[^>]+>/) + "\n"
646
-
656
+
657
+ #@log.debug 'before header'
647
658
  header = @raw_header[/<?dynarex (.*)?>/,1]
648
659
 
649
660
  r1 = /([\w\-]+\s*\=\s*'[^']*)'/
650
661
  r2 = /([\w\-]+\s*\=\s*"[^"]*)"/
651
662
 
652
663
  r = header.scan(/#{r1}|#{r2}/).map(&:compact).flatten
664
+ #@log.debug 'before each'
653
665
  r.each do |x|
654
666
 
655
667
  attr, val = x.split(/\s*=\s*["']/,2)
668
+ #@log.debug('dynarex: attr' + attr.inspect)
656
669
  self.method((attr + '=').to_sym).call(unescape val)
657
670
  end
658
671
 
659
672
  end
660
-
673
+ #log = Logger.new('/home/james/mm.log')
674
+ #@log.debug('dynarex: before root()')
661
675
  # if records already exist find the max id
662
676
  i = @doc.root.xpath('max(records/*/attribute::id)').to_i
663
-
677
+ #log.debug('dyanrex: after root()')
664
678
  raw_summary = schema[/\[([^\]]+)/,1]
665
679
 
666
680
  raw_lines = buffer.lines.to_a
@@ -741,62 +755,18 @@ EOF
741
755
 
742
756
  when '--+'
743
757
 
744
- self.summary[:rawdoc_type] = 'rowx'
745
- raw_lines.shift
746
-
747
- a3 = raw_lines.join.strip.split(/\n\n(?=\w+:)/)
748
-
749
- # get the fields
750
- a4 = a3.map{|x| x.scan(/^\w+(?=:)/)}.flatten(1).uniq
751
-
752
- abbrv_fields = a4.all? {|x| x.length == 1}
753
-
754
- a5 = a3.map do |xlines|
758
+ rowx(raw_lines)
755
759
 
756
- missing_fields = a4 - xlines.scan(/^\w+(?=:)/)
760
+ when '--#'
757
761
 
758
- r = xlines.split(/\n(\w+:.*)/m)
759
- missing_fields.map!{|x| x + ":"}
760
- key = (abbrv_fields ? @fields[0].to_s[0] : @fields.first.to_s) + ':'
761
-
762
- if missing_fields.include? key
763
- r.unshift key
764
- missing_fields.delete key
765
- end
766
-
767
- r += missing_fields
768
- r.join("\n")
769
-
770
- end
771
-
772
- xml = RowX.new(a5.join("\n").strip, level: 0).to_xml
773
-
774
- a2 = Rexle.new(xml).root.xpath('item').inject([]) do |r,x|
775
-
776
- r << @fields.map do |field|
777
- x.text(abbrv_fields ? field.to_s.chr : field.to_s )
778
- end
779
-
780
- end
781
-
782
- a2.compact!
783
-
784
- # if there is no field value for the first field then
785
- # the default_key is invalid. The default_key is changed to an ID.
786
- if a2.detect {|x| x.first == ''} then
787
- add_id(a2)
788
- else
762
+ self.summary[:rawdoc_type] = 'sectionx'
763
+ raw_lines.shift
789
764
 
790
- a3 = a2.map(&:first)
791
- add_id(a2) if a3 != a3.uniq
792
-
793
- end
794
-
795
- a2
765
+ raw_lines.join("\n").split(/(?=^#[^#])/).map {|x| [x.rstrip]}
796
766
 
797
767
  else
798
768
 
799
- raw_lines = raw_lines.join("\n").gsub(/^\s*#[^\n]+/,'').lines.to_a
769
+ raw_lines = raw_lines.join("\n").gsub(/^\s*#[^\n]+/,'').lines.to_a
800
770
  a2 = raw_lines.map.with_index do |x,i|
801
771
 
802
772
  next if x[/^\s+$|\n\s*#/]
@@ -869,7 +839,7 @@ EOF
869
839
  def dynarex_new(s)
870
840
  @schema = s
871
841
  ptrn = %r((\w+)\[?([^\]]+)?\]?\/(\w+)\(([^\)]+)\))
872
-
842
+ #@log.debug 'inside dynarex_new'
873
843
  if s.match(ptrn) then
874
844
  @root_name, raw_summary, record_name, raw_fields = s.match(ptrn).captures
875
845
  summary, fields = [raw_summary || '',raw_fields].map {|x| x.split(/,/).map &:strip}
@@ -886,12 +856,13 @@ EOF
886
856
  end
887
857
 
888
858
  format_mask = fields ? fields.map {|x| "[!%s]" % x}.join(' ') : ''
889
-
859
+ #@log.debug 'dynarex_new: before @summary'
890
860
  @summary = Hash[summary.zip([''] * summary.length).flatten.each_slice(2)\
891
861
  .map{|x1,x2| [x1.to_sym,x2]}]
892
862
  @summary.merge!({recordx_type: 'dynarex', format_mask: format_mask, schema: s})
893
863
  @records = {}
894
864
  @flat_records = {}
865
+ #@log.debug 'dynarex_new: before rebuild_doc'
895
866
  rebuild_doc
896
867
 
897
868
  end
@@ -901,13 +872,13 @@ EOF
901
872
  end
902
873
 
903
874
  def openx(s)
904
-
875
+ #@log.debug 'inside openx'
905
876
  if s[/</] then # xml
906
877
 
907
878
  buffer = s
908
879
 
909
880
  elsif s[/[\[\(]/] # schema
910
-
881
+ #@log.debug 'before dynarex_new'
911
882
  dynarex_new(s)
912
883
 
913
884
  elsif s[/^https?:\/\//] then # url
@@ -919,7 +890,7 @@ EOF
919
890
  raise DynarexException, 'file not found: ' + s unless File.exists? s
920
891
  buffer = File.read s
921
892
  end
922
-
893
+ #@log.debug 'openx: before buffer'
923
894
  if buffer then
924
895
 
925
896
  raw_stylesheet = buffer.slice!(/<\?xml-stylesheet[^>]+>/)
@@ -927,8 +898,11 @@ EOF
927
898
 
928
899
  @doc = Rexle.new(buffer) unless @doc
929
900
  end
930
-
901
+
902
+ #@log.debug('dynarex: before lement summary')
903
+ return if @doc.root.nil?
931
904
  e = @doc.root.element('summary')
905
+ #@log.debug('dynarex: \after element summary')
932
906
  @schema = e.text('schema')
933
907
  @root_name = @doc.root.name
934
908
  @summary = summary_to_h
@@ -1046,6 +1020,63 @@ EOF
1046
1020
 
1047
1021
  end
1048
1022
 
1023
+ def rowx(raw_lines)
1024
+
1025
+ self.summary[:rawdoc_type] = 'rowx'
1026
+ raw_lines.shift
1027
+
1028
+ a3 = raw_lines.join.strip.split(/\n\n(?=\w+:)/)
1029
+
1030
+ # get the fields
1031
+ a4 = a3.map{|x| x.scan(/^\w+(?=:)/)}.flatten(1).uniq
1032
+
1033
+ abbrv_fields = a4.all? {|x| x.length == 1}
1034
+
1035
+ a5 = a3.map do |xlines|
1036
+
1037
+ missing_fields = a4 - xlines.scan(/^\w+(?=:)/)
1038
+
1039
+ r = xlines.split(/\n(\w+:.*)/m)
1040
+ missing_fields.map!{|x| x + ":"}
1041
+ key = (abbrv_fields ? @fields[0].to_s[0] : @fields.first.to_s) + ':'
1042
+
1043
+ if missing_fields.include? key
1044
+ r.unshift key
1045
+ missing_fields.delete key
1046
+ end
1047
+
1048
+ r += missing_fields
1049
+ r.join("\n")
1050
+
1051
+ end
1052
+
1053
+ xml = RowX.new(a5.join("\n").strip, level: 0).to_xml
1054
+
1055
+ a2 = Rexle.new(xml).root.xpath('item').inject([]) do |r,x|
1056
+
1057
+ r << @fields.map do |field|
1058
+ x.text(abbrv_fields ? field.to_s.chr : field.to_s )
1059
+ end
1060
+
1061
+ end
1062
+
1063
+ a2.compact!
1064
+
1065
+ # if there is no field value for the first field then
1066
+ # the default_key is invalid. The default_key is changed to an ID.
1067
+ if a2.detect {|x| x.first == ''} then
1068
+ add_id(a2)
1069
+ else
1070
+
1071
+ a3 = a2.map(&:first)
1072
+ add_id(a2) if a3 != a3.uniq
1073
+
1074
+ end
1075
+
1076
+ a2
1077
+
1078
+ end
1079
+
1049
1080
  def sort_records
1050
1081
  xsl =<<XSL
1051
1082
  <?xml version="1.0" encoding="UTF-8"?>
@@ -1085,4 +1116,4 @@ XSL
1085
1116
  end
1086
1117
  end
1087
1118
 
1088
- end
1119
+ end
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: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -12,47 +12,27 @@ cert_chain:
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
14
  YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkW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
+ Pz2GWE7KigXTBg==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-02-12 00:00:00.000000000 Z
34
+ date: 2015-03-05 00:00:00.000000000 Z
35
35
  dependencies:
36
- - !ruby/object:Gem::Dependency
37
- name: rexle
38
- requirement: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '1.2'
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: 1.2.4
46
- type: :runtime
47
- prerelease: false
48
- version_requirements: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '1.2'
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: 1.2.4
56
36
  - !ruby/object:Gem::Dependency
57
37
  name: dynarex-import
58
38
  requirement: !ruby/object:Gem::Requirement
@@ -73,26 +53,6 @@ dependencies:
73
53
  - - ">="
74
54
  - !ruby/object:Gem::Version
75
55
  version: 0.2.2
76
- - !ruby/object:Gem::Dependency
77
- name: line-tree
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.5'
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: 0.5.0
86
- type: :runtime
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - "~>"
91
- - !ruby/object:Gem::Version
92
- version: '0.5'
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: 0.5.0
96
56
  - !ruby/object:Gem::Dependency
97
57
  name: rexle-builder
98
58
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +122,7 @@ dependencies:
162
122
  version: '0.1'
163
123
  - - ">="
164
124
  - !ruby/object:Gem::Version
165
- version: 0.1.12
125
+ version: 0.1.18
166
126
  type: :runtime
167
127
  prerelease: false
168
128
  version_requirements: !ruby/object:Gem::Requirement
@@ -172,7 +132,7 @@ dependencies:
172
132
  version: '0.1'
173
133
  - - ">="
174
134
  - !ruby/object:Gem::Version
175
- version: 0.1.12
135
+ version: 0.1.18
176
136
  - !ruby/object:Gem::Dependency
177
137
  name: rxraw-lineparser
178
138
  requirement: !ruby/object:Gem::Requirement
@@ -199,20 +159,20 @@ dependencies:
199
159
  requirements:
200
160
  - - "~>"
201
161
  - !ruby/object:Gem::Version
202
- version: '0.3'
162
+ version: '0.4'
203
163
  - - ">="
204
164
  - !ruby/object:Gem::Version
205
- version: 0.3.1
165
+ version: 0.4.1
206
166
  type: :runtime
207
167
  prerelease: false
208
168
  version_requirements: !ruby/object:Gem::Requirement
209
169
  requirements:
210
170
  - - "~>"
211
171
  - !ruby/object:Gem::Version
212
- version: '0.3'
172
+ version: '0.4'
213
173
  - - ">="
214
174
  - !ruby/object:Gem::Version
215
- version: 0.3.1
175
+ version: 0.4.1
216
176
  - !ruby/object:Gem::Dependency
217
177
  name: nokogiri
218
178
  requirement: !ruby/object:Gem::Requirement
@@ -259,20 +219,20 @@ dependencies:
259
219
  requirements:
260
220
  - - "~>"
261
221
  - !ruby/object:Gem::Version
262
- version: '0.1'
222
+ version: '0.2'
263
223
  - - ">="
264
224
  - !ruby/object:Gem::Version
265
- version: 0.1.14
225
+ version: 0.2.1
266
226
  type: :runtime
267
227
  prerelease: false
268
228
  version_requirements: !ruby/object:Gem::Requirement
269
229
  requirements:
270
230
  - - "~>"
271
231
  - !ruby/object:Gem::Version
272
- version: '0.1'
232
+ version: '0.2'
273
233
  - - ">="
274
234
  - !ruby/object:Gem::Version
275
- version: 0.1.14
235
+ version: 0.2.1
276
236
  description:
277
237
  email: james@r0bertson.co.uk
278
238
  executables: []
metadata.gz.sig CHANGED
Binary file