kvx 0.9.3 → 0.9.8
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/kvx.rb +70 -17
- metadata +2 -2
- 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: e33cb28dd286c387e4d88e2135d963c8fcf4900f820ef029c9070e607dc12a69
|
4
|
+
data.tar.gz: 0da86a16d3fde9067799c02220872a207c0356118cab174e2c0eabe0c6e4aa87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a97b15609374f31dad6d619f215636b293269ac4fa5a908e0077ce9cdb2559c16e9fe7c10e291b1ed273b7a53dc91a03de77a0959f265c94285a5cd9f72094e1
|
7
|
+
data.tar.gz: 6113ee553354238630288da7d5bb40c96f6f9104b985fb514211b431ac1074e153b8931600a5a111bffd0bca9e7b5c02436e2b16d878302c1c405263c2278607
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/kvx.rb
CHANGED
@@ -36,7 +36,7 @@ class Kvx
|
|
36
36
|
|
37
37
|
def initialize(x=nil, attributes: {}, debug: false)
|
38
38
|
|
39
|
-
@header =
|
39
|
+
@header = attributes.any?
|
40
40
|
@identifier = 'kvx'
|
41
41
|
@summary = {}
|
42
42
|
@ignore_blank_lines ||= false
|
@@ -76,12 +76,23 @@ class Kvx
|
|
76
76
|
FileX.write filename, self.to_s
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
# flattening is helpful when passing the Hash object to
|
80
|
+
# RecordX as a new record
|
81
|
+
#
|
82
|
+
def to_h(flatten: false)
|
80
83
|
|
81
84
|
if @summary.empty? then
|
85
|
+
|
82
86
|
deep_clone @body
|
87
|
+
|
83
88
|
else
|
84
|
-
|
89
|
+
|
90
|
+
if flatten then
|
91
|
+
@summary.merge @body
|
92
|
+
else
|
93
|
+
{summary: deep_clone(@summary), body: deep_clone(@body)}
|
94
|
+
end
|
95
|
+
|
85
96
|
end
|
86
97
|
|
87
98
|
end
|
@@ -137,8 +148,12 @@ class Kvx
|
|
137
148
|
header = '<?' + @identifier
|
138
149
|
header += attr
|
139
150
|
header += "?>\n"
|
140
|
-
|
141
|
-
|
151
|
+
|
152
|
+
if @summary and @summary.any? then
|
153
|
+
header += scan_to_s @summary
|
154
|
+
header += "\n----------------------------------\n\n"
|
155
|
+
end
|
156
|
+
|
142
157
|
end
|
143
158
|
|
144
159
|
# -- use the nested description Hash object if there are multiple lines
|
@@ -170,6 +185,13 @@ class Kvx
|
|
170
185
|
doc.xml(options)
|
171
186
|
|
172
187
|
end
|
188
|
+
|
189
|
+
# used by RecordX to update a KVX record
|
190
|
+
# id is unnecssary because there is only 1 record mapped to RecordX
|
191
|
+
#
|
192
|
+
def update(id=nil, hpair={})
|
193
|
+
@body.merge! hpair
|
194
|
+
end
|
173
195
|
|
174
196
|
private
|
175
197
|
|
@@ -222,7 +244,10 @@ class Kvx
|
|
222
244
|
def make_xml(h)
|
223
245
|
|
224
246
|
puts 'inside make_xml: ' + h.inspect if @debug
|
225
|
-
|
247
|
+
h2 = h.clone
|
248
|
+
h2.each {|key,value| value.delete :items if value.is_a?(Hash) }
|
249
|
+
|
250
|
+
RexleBuilder.new(h2, debug: false).to_a[3..-1]
|
226
251
|
end
|
227
252
|
|
228
253
|
def parse_string(s)
|
@@ -270,7 +295,7 @@ class Kvx
|
|
270
295
|
@attributes.merge! attr
|
271
296
|
@header = true
|
272
297
|
body, summary = a.join.strip.split(/^----*$/).reverse
|
273
|
-
@summary = scan_to_h summary
|
298
|
+
@summary = scan_to_h summary if summary
|
274
299
|
|
275
300
|
body
|
276
301
|
else
|
@@ -301,22 +326,47 @@ class Kvx
|
|
301
326
|
|
302
327
|
|
303
328
|
def scan_to_h(txt)
|
329
|
+
|
330
|
+
txt.gsub!(/^\w+:(?=$)/,'\0 ')
|
331
|
+
puts 'txt:' + txt.inspect if @debug
|
332
|
+
|
333
|
+
# auto indent any multiline values which aren't already indented
|
334
|
+
|
335
|
+
indent = ''
|
304
336
|
|
337
|
+
lines = txt.gsub(/^-+$/m,'').lines.map do |line|
|
338
|
+
|
339
|
+
if not line[/^ *[^:]+:|^ +/] then
|
340
|
+
indent + ' ' + line
|
341
|
+
else
|
342
|
+
indent = line[/^ +/] || ''
|
343
|
+
line
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
347
|
+
puts ('lines: ' + lines.inspect).debug if @debug
|
348
|
+
|
305
349
|
puts ('inside scan_to_h').info if @debug
|
306
|
-
raw_a = LineTree.new(
|
307
|
-
|
350
|
+
raw_a = LineTree.new(lines.join.gsub(/(^-*$)|(^ *#.*)/,'').strip,
|
351
|
+
ignore_blank_lines: @ignore_blank_lines).to_a
|
308
352
|
puts ('raw_a: ' + raw_a.inspect).debug if @debug
|
309
353
|
|
310
354
|
# if there are any orphan lines which aren't nested underneath a
|
311
355
|
# label, they will be fixed using the following statement
|
312
356
|
|
313
|
-
a = raw_a.chunk {|x| x[0][/^[^:]
|
357
|
+
a = raw_a.chunk {|x| x[0][/^[^:]+:/]}.inject([]) do |r,y|
|
358
|
+
|
359
|
+
puts 'r: ' + r.inspect if @debug
|
360
|
+
|
314
361
|
if r.last and !y.first[/[^:]+:/] then
|
315
362
|
r.last << y.last[-1]
|
316
363
|
else
|
364
|
+
puts 'y: ' + y.inspect if @debug
|
317
365
|
r << y.last[-1]
|
318
366
|
end
|
367
|
+
|
319
368
|
r
|
369
|
+
|
320
370
|
end
|
321
371
|
|
322
372
|
@body = a.inject({}) do |r, line|
|
@@ -324,13 +374,16 @@ class Kvx
|
|
324
374
|
s = line.shift
|
325
375
|
puts ('s: ' + s.inspect).debug if @debug
|
326
376
|
|
327
|
-
if line.join.length > 0 then
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
377
|
+
if line.join.length > 0 then
|
378
|
+
|
379
|
+
puts 'line: ' + line.inspect if @debug
|
380
|
+
|
381
|
+
padding = line[0].length < 2 ? "\n" : "\n "
|
382
|
+
s10 = line.map{|x| x.join(padding)}.join("\n")
|
383
|
+
|
384
|
+
r2 = if s10[/^[^:]+:[\n ]/] then
|
332
385
|
|
333
|
-
scan_to_h(
|
386
|
+
scan_to_h(s10)
|
334
387
|
|
335
388
|
else
|
336
389
|
|
@@ -356,7 +409,7 @@ class Kvx
|
|
356
409
|
|
357
410
|
else
|
358
411
|
|
359
|
-
value, name = s.split(
|
412
|
+
value, name = s.split(/: */,2).reverse
|
360
413
|
name ||= 'description'
|
361
414
|
v = value =~ /^\{\s*\}$/ ? {} : value.to_s
|
362
415
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kvx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
m/+jxdgFjKKGxeZqunu9cp5ca9wSjjtKh/VA/3xZtPwokCa7vCMB+ZxUP0jvd++u
|
36
36
|
OTXy8k/zqddw/VfD/It1UUK4
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2021-
|
38
|
+
date: 2021-05-22 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: line-tree
|
metadata.gz.sig
CHANGED
Binary file
|