rexle-builder 1.0.1 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eda1c60846fb9f76df929bf427ce589c969482ad8e7fefb5fb3f2ece28acd54a
4
- data.tar.gz: 337188bbc932c1824c70a753da66c5fa00216e6500c7d673adf4796371273c5d
3
+ metadata.gz: d6c908421b55a41fe3988edff4238b011358ba5b78440036593ebf4b5ff65bb7
4
+ data.tar.gz: 150737d9be007c7c9d48fe30be8f606efe2b66bb3bfcbb69f3ea18b298cded1b
5
5
  SHA512:
6
- metadata.gz: 6cf481ebbddf24c43907ace9c67892029f4f392e5404108c54c38ea363e079ba0ae94db52f38d714b3ee426121dee83aa59487ea307433110cb0e0a3199131bd
7
- data.tar.gz: 3cfd8fbf699b75baa0e379519101205b4cf43496469a9c12cb84d111cf1c66974f59721aa6431734d674d078e8d59d78965a5374db1a5f6b61646262f7ef714b
6
+ metadata.gz: 29db012b7fcd96b56a5490afda250c9f7791c1d8354f0de0a66f40c4bf57689d130ca9db6077242a624af0882f61904c0ea77e186df480fe1194519bdadd398f
7
+ data.tar.gz: a56a35dd95093c7545bed8b7e2f5c9584947ccef4348fe2a5ccddc612167c89165dca45a79f1daa4a10dd12fb6998f5f33cbff428fe4bf23dcda58280947765c
checksums.yaml.gz.sig CHANGED
@@ -1 +1 @@
1
- @)���{�ٛ}�ү�a�z���c-��D�L�Q}�@���N��[���h0P�י� �$ �+(5���oM��G#R,jY�}��v�
1
+ E*�56����
data/lib/rexle-builder.rb CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
  class RexleArray < Array
7
-
7
+
8
8
  def initialize(raw_a)
9
9
  a = raw_a.first.is_a?(Array) ? raw_a : [raw_a]
10
10
  super(a)
@@ -19,20 +19,20 @@ class RexleBuilder
19
19
  yield(self.new(debug: debug))
20
20
 
21
21
  end
22
-
22
+
23
23
  def initialize(obj=nil, root: 'root', debug: false)
24
-
24
+
25
25
  @debug = debug
26
26
  @a = []
27
27
  @current_a = @a
28
28
  @namespace = nil
29
-
29
+
30
30
  if obj.is_a? Hash then
31
-
32
- key = obj.keys.first
33
-
31
+
32
+ key = obj.keys.first
33
+
34
34
  if obj.length > 1 or obj[key].is_a?(Array) or obj[key].is_a?(String) then
35
- self.send(root.to_sym) { buildx obj}
35
+ self.send(root.to_sym) { buildx obj}
36
36
  else
37
37
  self.send(key.to_sym) {buildx obj[key]}
38
38
  end
@@ -50,91 +50,127 @@ class RexleBuilder
50
50
  end
51
51
 
52
52
  def method_missing(sym, *args)
53
-
53
+
54
54
  puts 'args: ' + args.inspect if @debug
55
-
56
- value = args.shift if args.first.is_a? String
57
-
58
- # The obj is an optional Hash object used to build nested XML
55
+
56
+ value = args.find {|x| x.is_a? String} || ''
57
+ attributes, obj = args.select {|x| x.is_a? Hash}
58
+
59
+ # The obj is an optional Hash object used to build nested XML
59
60
  # after the current element
60
- attributes, obj = args
61
-
61
+
62
62
  if value =~ /^<.*>$/ then
63
-
63
+
64
64
  a = [
65
- sym.to_s,
66
- attributes,
65
+ sym.to_s,
66
+ attributes,
67
67
  *Rexle.new("<root>%s</root>" % value, debug: @debug).to_a[2..-1]
68
68
  ]
69
-
69
+
70
70
  end
71
-
71
+
72
+
73
+ # reserved keywords are masked with ._ e.g. ._method_missing
74
+ a ||= [sym.to_s.sub(/^(?:\._|_)/,'').sub(/^cdata!$/,'![')\
75
+ .sub(/^comment!$/, '!-'), attributes || {}, value || '']
72
76
  if @debug then
73
77
  puts 'sym: ' + sym.inspect
74
78
  puts 'args: ' + args.inspect
79
+ puts 'obj: ' + obj.inspect
80
+ puts 'a: ' + a.inspect
75
81
  end
76
-
77
- # reserved keywords are masked with ._ e.g. ._method_missing
78
- a ||= [sym.to_s.sub(/^(?:\._|_)/,'').sub(/^cdata!$/,'![')\
79
- .sub(/^comment!$/, '!-'), attributes || {}, value || '']
80
-
82
+
81
83
  a.concat RexleBuilder.new(obj, debug: false).to_a[3..-1] if obj
82
84
 
83
- if @namespace then
85
+ if @namespace then
84
86
  a.first.prepend(@namespace + ':')
85
- @namespace = nil
87
+ @namespace = nil
86
88
  end
87
89
 
88
90
  @current_a << a
89
-
91
+ puts '@current_a, before block_given : ' + @current_a.inspect if @debug
92
+
90
93
  if block_given? then
91
-
94
+
92
95
  prev_a = @current_a
93
96
  @current_a = a
94
-
95
- r = yield()
96
-
97
- @current_a.concat r if r.class == RexleArray
98
- @current_a = prev_a
99
-
97
+
98
+ r = yield()
99
+
100
+ if @debug then
101
+ puts 'r: ' + r.inspect
102
+ puts 'r.class: ' + r.class.inspect
103
+ end
104
+
105
+ return r if r == @a.first
106
+ @current_a.concat r if r.is_a? Array
107
+ puts '@current_a ' + @current_a.inspect if @debug
108
+ @current_a = prev_a
109
+ return @a.first
110
+
100
111
  end
101
-
102
- @a.first
112
+
113
+ #@a.first
114
+ nil
103
115
  end
104
-
116
+
105
117
  private
106
-
118
+
107
119
  # build from a Hash object
108
120
  #
109
121
  def buildx( h)
110
122
 
111
- h.each_pair do |key, value|
123
+ puts 'buildx: ' + h.inspect if @debug
124
+ # the following statement prevents duplicate elements where 1 key is
125
+ # represented by a String and the other by a symbol.
126
+ #
127
+ h2 = h.map {|x| [x[0].to_sym, x[1]]}.to_h
128
+
129
+ h2.each_pair do |key, value|
112
130
 
113
131
  if value.is_a? Hash then
114
-
115
- self.send(key.to_sym) do
132
+ puts 'buildx found Hash' + value.inspect if @debug
133
+ self.send(key.to_sym) do
116
134
  buildx value
135
+ nil
117
136
  end
118
-
119
- elsif value.is_a? Array
120
-
137
+
138
+ elsif value.is_a?(Array) and value.first.is_a? Hash
139
+
140
+ puts 'buildx found Array' + value.inspect if @debug
141
+ puts 'key:' + key.inspect if @debug
142
+
121
143
  self.send(key.to_sym) do
122
-
123
- if value.first.is_a? Hash then
124
- value.map {|x| buildx x}
125
- else
126
- RexleArray.new value
144
+
145
+ r2= []
146
+ value.each do |x|
147
+
148
+ if x.is_a? Hash then
149
+ puts 'x:' + x.inspect if @debug
150
+ buildx x
151
+ nil
152
+ else
153
+ puts 'x2:' + x.inspect if @debug
154
+ r2 << x
155
+ end
156
+
127
157
  end
128
-
158
+
159
+ r2
129
160
  end
130
-
161
+
131
162
  else
132
-
133
- self.send(key.to_sym, value.to_s)
134
-
163
+
164
+ puts 'buildx found other' + value.inspect if @debug
165
+ if value.is_a? String then
166
+ self.send(key.to_sym, value.to_s)
167
+ else
168
+ self.send(key.to_sym) {[value]}
169
+ end
170
+
135
171
  end
136
172
  end
137
173
 
138
- end
174
+ end
139
175
 
140
176
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexle-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,35 +10,36 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwNTAxMTgyMTU4WhcN
15
- MjEwNTAxMTgyMTU4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDXvcGF
17
- KAsFoSJW5WibJ3BCxoe5RyUNGARFsSo+Y755n9YmTEoL9jCNkxHCyZAPJSXeZJlV
18
- jM1LqYD6n9MW73o0B7vy9Rq1n49cWIliXYrkIvhLlS7qviVg+ij8/o36LVeK4/4d
19
- Z5d+jRyr6tovVn6Hlqs8qoMdI4lOj1f3yb2kFhbkW2Zx/O+4T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yS9ixjhp7e2dejAmBgNVHREEHzAdgRtnZW1tYXN0ZXJAamFt
28
+ ZXNyb2JlcnRzb24uZXUwJgYDVR0SBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
29
+ c29uLmV1MA0GCSqGSIb3DQEBCwUAA4IBgQANTkbRlCnyKnC93YfSYYZZIY2yG3w4
30
+ aMC5NdlJbJKqNS5iFJFGzQmQFh64qphNYS/ER71XjeUcpQmL3G8CStlE2/Pgmw3q
31
+ AxGZQicTWSz7oZy0YWeAXiHu+Z+H5N9ar7r6cbN7e1X7100rXJOIoRbV30/7X2nd
32
+ oqq/CmaXtg5Tbr+pV461riwkEd+zq98EhVw8Mud0YOZ7QBGY1i1xK6DpTLWgzsiI
33
+ dCDj3IztA2K8hUJpP5aNw5nAGcLc/FxxGDySI2cQc+fDsM6RfFjch8EUd125yvRe
34
+ ab0Xx0Rsvj2/Z63HLArC6rESIzZVpt4FAOBlCzOtMJEC9SMBMM7+sbMbwRxoTCKj
35
+ VmHj3sRQB3mQj4qN3dd241Ea4y2eTa/mML8gvkx84jAYr/nmQc8tRV64bnp2G01a
36
+ w7Z+7EzJFzhHpXYm4QBYR+qb81pB/ZX0LWtVs/2jjCWoCOOdIuH/jh+DzQk4Qhby
37
+ R02xW5SGXEOiylE3Q9SDqGfvomcQ8ENDYts=
37
38
  -----END CERTIFICATE-----
38
- date: 2020-06-22 00:00:00.000000000 Z
39
+ date: 2022-07-24 00:00:00.000000000 Z
39
40
  dependencies: []
40
41
  description:
41
- email: james@jamesrobertson.eu
42
+ email: digital.robertson@gmail.com
42
43
  executables: []
43
44
  extensions: []
44
45
  extra_rdoc_files: []
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  - !ruby/object:Gem::Version
64
65
  version: '0'
65
66
  requirements: []
66
- rubygems_version: 3.0.3
67
+ rubygems_version: 3.3.7
67
68
  signing_key:
68
69
  specification_version: 4
69
70
  summary: Generates XML, by producing an array of raw XML elements which can parsed
metadata.gz.sig CHANGED
Binary file