dxlite 0.2.7 → 0.3.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/dxlite.rb +108 -47
- metadata +12 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6638bca4c2fef3679ec9d456318f51b51eeeb49230afadbd1baa8af4308620ca
|
4
|
+
data.tar.gz: 1fcaedf6a4692a244e5930ed1d8ec10e7784b5003958faafb45b8e32cdaa707a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a8938acfd2116234f3a750c9e007adae6e2bc7cb894379702aebe2730b8a601c88f178a490f4b260275e5682c211efee2c5c9da57b9fa645f5146b66a5c7d9
|
7
|
+
data.tar.gz: ec2fde50afa20bbea953fc3ffb503ae07f160580248ecde88e99f1c272f64404cf6bea099c75e4286f411f3c83df27516df39394c27e78d3bc1846e2fce2b88d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dxlite.rb
CHANGED
@@ -14,14 +14,17 @@ class DxLite
|
|
14
14
|
attr_accessor :summary
|
15
15
|
attr_reader :records
|
16
16
|
|
17
|
-
def initialize(s, filepath: nil, debug: false)
|
17
|
+
def initialize(s=nil, filepath: nil, debug: false)
|
18
18
|
|
19
19
|
@filepath, @debug = filepath, debug
|
20
20
|
|
21
|
+
return unless s
|
21
22
|
buffer, type = RXFHelper.read(s)
|
22
23
|
puts 'type: ' + type.inspect if @debug
|
23
24
|
puts 'buffer: ' + buffer.inspect if @debug
|
24
|
-
|
25
|
+
|
26
|
+
@records = []
|
27
|
+
|
25
28
|
case type
|
26
29
|
|
27
30
|
when :file
|
@@ -31,7 +34,7 @@ class DxLite
|
|
31
34
|
when :text
|
32
35
|
|
33
36
|
@summary = {schema: s}
|
34
|
-
|
37
|
+
|
35
38
|
|
36
39
|
when :url
|
37
40
|
|
@@ -39,51 +42,28 @@ class DxLite
|
|
39
42
|
|
40
43
|
end
|
41
44
|
|
42
|
-
|
45
|
+
puts '@summary: ' + @summary.inspect
|
43
46
|
@schema = @summary[:schema]
|
44
47
|
|
45
48
|
summary_attributes = {
|
46
49
|
recordx_type: 'dynarex',
|
47
|
-
default_key: @schema[/(?<=\()\w+/]
|
50
|
+
default_key: @schema[/(?<=\()\w+/]
|
48
51
|
}
|
49
|
-
|
52
|
+
|
53
|
+
puts 'before merge' if @debug
|
50
54
|
@summary.merge!(summary_attributes)
|
51
55
|
|
52
56
|
summary = @summary[:schema][/(?<=\[)[^\]]+/]
|
53
57
|
|
54
58
|
if summary then
|
55
|
-
@summary.merge! summary.split(',').map {|x|[x.strip, nil] }.to_h
|
56
|
-
end
|
57
|
-
|
58
|
-
# for each summary item create get and set methods
|
59
|
-
|
60
|
-
@summary.each do |key, value|
|
61
|
-
|
62
|
-
define_singleton_method(key) { @summary[key] }
|
63
|
-
|
64
|
-
define_singleton_method (key.to_s + '=').to_sym do |value|
|
65
|
-
@summary[key] = value
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
@fields = @summary[:schema][/(?<=\()[^\)]+/].split(',').map(&:strip)
|
71
|
-
|
72
|
-
@fields.each do |x|
|
73
59
|
|
74
|
-
|
75
|
-
|
76
|
-
@records.select {|rec| find_record(rec[:body], value, x) }
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
define_singleton_method ('find_by_' + x).to_sym do |value|
|
81
|
-
|
82
|
-
@records.find {|rec| find_record(rec[:body], value, x) }
|
83
|
-
|
60
|
+
summary.split(/ *, */).each do |x|
|
61
|
+
@summary[x] = nil unless @summary[x]
|
84
62
|
end
|
85
|
-
|
86
|
-
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
make_methods()
|
87
67
|
|
88
68
|
end
|
89
69
|
|
@@ -103,11 +83,17 @@ class DxLite
|
|
103
83
|
@records.delete found if found
|
104
84
|
end
|
105
85
|
|
106
|
-
def create(
|
86
|
+
def create(rawh, id: nil, custom_attributes: {created: Time.now})
|
107
87
|
|
108
88
|
id ||= @records.map {|x| x[:id].to_i}.max.to_i + 1
|
109
89
|
h2 = custom_attributes
|
110
|
-
|
90
|
+
h = fields.map {|x| [x.to_sym, nil] }.to_h.merge(rawh)
|
91
|
+
@records << {id: id.to_s, created: h2[:created], last_modified: nil,
|
92
|
+
body: h}
|
93
|
+
end
|
94
|
+
|
95
|
+
def fields()
|
96
|
+
@fields
|
111
97
|
end
|
112
98
|
|
113
99
|
def inspect()
|
@@ -127,7 +113,7 @@ class DxLite
|
|
127
113
|
end
|
128
114
|
|
129
115
|
obj.each do |x|
|
130
|
-
puts 'x: ' + x.inspect if @debug
|
116
|
+
#puts 'x: ' + x.inspect if @debug
|
131
117
|
self.create x, id: nil
|
132
118
|
end
|
133
119
|
|
@@ -137,12 +123,45 @@ class DxLite
|
|
137
123
|
end
|
138
124
|
|
139
125
|
alias import parse
|
126
|
+
|
127
|
+
def parse_xml(buffer)
|
128
|
+
|
129
|
+
doc = Rexle.new(buffer)
|
130
|
+
|
131
|
+
asummary = doc.root.xpath('summary/*').map do |node|
|
132
|
+
puts 'node: ' + node.xml.inspect if @debug
|
133
|
+
[node.name, node.text.to_s]
|
134
|
+
end
|
135
|
+
|
136
|
+
summary = Hash[asummary]
|
137
|
+
summary[:schema] = summary['schema']
|
138
|
+
%w(recordx_type format_mask schema).each {|x| summary.delete x}
|
139
|
+
|
140
|
+
schema = summary[:schema]
|
141
|
+
puts 'schema: ' + schema.inspect if @debug
|
142
|
+
|
143
|
+
@fields = schema[/\(([^\)]+)/,1].split(/ *, +/)
|
144
|
+
puts 'fields: ' + @fields.inspect if @debug
|
145
|
+
|
146
|
+
a = doc.root.xpath('records/*').each do |node|
|
147
|
+
|
148
|
+
h = Hash[@fields.map {|field| [field.to_sym, node.text(field).to_s] }]
|
149
|
+
self.create h, id: nil
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
@summary = summary
|
154
|
+
|
155
|
+
end
|
140
156
|
|
141
157
|
def save(file=@filepath)
|
142
|
-
File.
|
158
|
+
s = File.extname(file) == '.json' ? to_json() : to_xml()
|
159
|
+
File.write file, s
|
143
160
|
end
|
144
161
|
|
145
|
-
|
162
|
+
def to_a()
|
163
|
+
@records.map {|x| x[:body]}
|
164
|
+
end
|
146
165
|
|
147
166
|
def to_h()
|
148
167
|
|
@@ -212,16 +231,58 @@ class DxLite
|
|
212
231
|
value.is_a?(Regexp) ? rec[x.to_sym] =~ value : rec[x.to_sym] == value
|
213
232
|
end
|
214
233
|
|
215
|
-
def
|
234
|
+
def make_methods()
|
216
235
|
|
217
|
-
|
218
|
-
puts 'h1:' + h1.inspect if @debug
|
236
|
+
# for each summary item create get and set methods
|
219
237
|
|
220
|
-
|
238
|
+
@summary.each do |key, value|
|
239
|
+
|
240
|
+
define_singleton_method(key) { @summary[key] }
|
241
|
+
|
242
|
+
define_singleton_method (key.to_s + '=').to_sym do |value|
|
243
|
+
@summary[key] = value
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
221
247
|
|
222
|
-
@
|
223
|
-
|
248
|
+
@fields = @summary[:schema][/(?<=\()[^\)]+/].split(',').map(&:strip)
|
249
|
+
|
250
|
+
@fields.each do |x|
|
251
|
+
|
252
|
+
define_singleton_method ('find_all_by_' + x).to_sym do |value|
|
253
|
+
|
254
|
+
@records.select {|rec| find_record(rec[:body], value, x) }
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
define_singleton_method ('find_by_' + x).to_sym do |value|
|
259
|
+
|
260
|
+
@records.find {|rec| find_record(rec[:body], value, x) }
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
224
265
|
|
225
266
|
end
|
226
267
|
|
268
|
+
def read(buffer)
|
269
|
+
|
270
|
+
if buffer[0] == '<' then
|
271
|
+
|
272
|
+
parse_xml buffer
|
273
|
+
|
274
|
+
else
|
275
|
+
|
276
|
+
h1 = JSON.parse(buffer, symbolize_names: true)
|
277
|
+
#puts 'h1:' + h1.inspect if @debug
|
278
|
+
|
279
|
+
h = h1[h1.keys.first]
|
280
|
+
|
281
|
+
@summary = h[:summary]
|
282
|
+
@records = h[:records].map {|x| x[x.keys.first]}
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
227
288
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dxlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
dwbAN6/wokoLVZAiMRG1vZlI6RhtSOTHvFHbfBE5JI9rhjRtui8yeV+t8iI8G4Zs
|
36
36
|
2NszuYzdlVfzlrUiPWY5jL9P
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-01-23 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: recordx
|
@@ -61,22 +61,22 @@ dependencies:
|
|
61
61
|
name: rxfhelper
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 1.0.0
|
67
64
|
- - "~>"
|
68
65
|
- !ruby/object:Gem::Version
|
69
|
-
version: '1.
|
66
|
+
version: '1.1'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.3
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 1.0.0
|
77
74
|
- - "~>"
|
78
75
|
- !ruby/object:Gem::Version
|
79
|
-
version: '1.
|
76
|
+
version: '1.1'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.1.3
|
80
80
|
description:
|
81
81
|
email: james@jamesrobertson.eu
|
82
82
|
executables: []
|
@@ -103,7 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.10
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: Handles Dynarex documents (in JSON format) faster and with less overheads.
|
metadata.gz.sig
CHANGED
Binary file
|