kvx 0.9.2 → 0.9.7

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/kvx.rb +79 -18
  5. metadata +2 -2
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96cfc3e8b1006b34c301f6753f35be06d1488fbfc3233094269c0d6cf61560a6
4
- data.tar.gz: d706f6a62e289443c0fc90a09a49ca29a2001de59e8f59420da4cd3cb345d3a0
3
+ metadata.gz: '03690b30a2cce31295d0d6eeffc8c142785ab25efb0bad30328a41121d0f1e28'
4
+ data.tar.gz: d16ee75eb0d6aec1641b9b1a544e459623195889860f579414f8b338151cdb08
5
5
  SHA512:
6
- metadata.gz: da3953a0cbfbf07a8116eaa7365c8d0e0074c356d57e4f1c894f85c2eb6cbe6a218db580c1cf066ba15153eb193fe097c978e2d4f4cbe134fb7552052166831d
7
- data.tar.gz: 9291206b7516b575363a4965fc1d3fa816e888f35a768c286162df1bebc5528aa0e9dd70659f436472424e73a51e30711317fd18faea435bb4c47626983afe08
6
+ metadata.gz: 0e5cfff4834e5f080f983608178807c0483db5073cb158cc64ccc1b95b05bd0dd2afe7d0e25dbcafb8648d08ea1b803c6f914e1907bc5f264a8c5510d05262b2
7
+ data.tar.gz: c8d3f742947f5dd4f10a54223ffb27b09c131d36ff443f2b2790120b16a570a9e253cf1677fd88f637158d0c3ee2f87d720530dd08655c17edb9f9854376cb05
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 = false
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
- def to_h()
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
- {summary: deep_clone(@summary), body: deep_clone(@body)}
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
- header += scan_to_s @summary
141
- header += "\n----------------------------------\n\n"
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
@@ -146,8 +161,17 @@ class Kvx
146
161
 
147
162
  @body.each do |key, value|
148
163
 
149
- h[key] = value.is_a?(String) ? value : \
164
+ h[key] = if value.is_a?(String) then
165
+
166
+ if value.lines.length < 2 then
167
+ value
168
+ else
169
+ "\n" + value.lines.map {|x| ' ' + x }.join
170
+ end
171
+
172
+ else
150
173
  "\n" + value[:description].lines.map {|x| ' ' + x }.join
174
+ end
151
175
 
152
176
  end
153
177
 
@@ -161,6 +185,13 @@ class Kvx
161
185
  doc.xml(options)
162
186
 
163
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
164
195
 
165
196
  private
166
197
 
@@ -213,7 +244,10 @@ class Kvx
213
244
  def make_xml(h)
214
245
 
215
246
  puts 'inside make_xml: ' + h.inspect if @debug
216
- RexleBuilder.new(h, debug: false).to_a[3..-1]
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]
217
251
  end
218
252
 
219
253
  def parse_string(s)
@@ -261,7 +295,7 @@ class Kvx
261
295
  @attributes.merge! attr
262
296
  @header = true
263
297
  body, summary = a.join.strip.split(/^----*$/).reverse
264
- @summary = scan_to_h summary
298
+ @summary = scan_to_h summary if summary
265
299
 
266
300
  body
267
301
  else
@@ -292,22 +326,46 @@ class Kvx
292
326
 
293
327
 
294
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 = ''
336
+
337
+ lines = txt.gsub(/^-+$/m,'').lines.map do |line|
338
+
339
+ if not line[/^ *\w+:|^ +/] then
340
+ indent + ' ' + line
341
+ else
342
+ indent = line[/^ +/] || ''
343
+ line
344
+ end
345
+
346
+ end
295
347
 
296
348
  puts ('inside scan_to_h').info if @debug
297
- raw_a = LineTree.new(txt.gsub(/(^-*$)|(#.*)/,'').strip,
298
- ignore_blank_lines: @ignore_blank_lines).to_a
349
+ raw_a = LineTree.new(lines.join.gsub(/(^-*$)|(^ *#.*)/,'').strip,
350
+ ignore_blank_lines: @ignore_blank_lines).to_a
299
351
  puts ('raw_a: ' + raw_a.inspect).debug if @debug
300
352
 
301
353
  # if there are any orphan lines which aren't nested underneath a
302
354
  # label, they will be fixed using the following statement
303
355
 
304
- a = raw_a.chunk {|x| x[0][/^[^:]+:|.*/]}.inject([]) do |r,y|
356
+ a = raw_a.chunk {|x| x[0][/^[^:]+:/]}.inject([]) do |r,y|
357
+
358
+ puts 'r: ' + r.inspect if @debug
359
+
305
360
  if r.last and !y.first[/[^:]+:/] then
306
361
  r.last << y.last[-1]
307
362
  else
363
+ puts 'y: ' + y.inspect if @debug
308
364
  r << y.last[-1]
309
365
  end
366
+
310
367
  r
368
+
311
369
  end
312
370
 
313
371
  @body = a.inject({}) do |r, line|
@@ -315,13 +373,16 @@ class Kvx
315
373
  s = line.shift
316
374
  puts ('s: ' + s.inspect).debug if @debug
317
375
 
318
- if line.join.length > 0 then
319
-
320
- r2 = if line[0][0][/^[^:]+:/] then
321
-
322
- padding = line[0].length < 2 ? "\n" : "\n "
376
+ if line.join.length > 0 then
377
+
378
+ puts 'line: ' + line.inspect if @debug
379
+
380
+ padding = line[0].length < 2 ? "\n" : "\n "
381
+ s10 = line.map{|x| x.join(padding)}.join("\n")
382
+
383
+ r2 = if s10[/^[^:]+:[\n ]/] then
323
384
 
324
- scan_to_h(line.map{|x| x.join(padding)}.join("\n"))
385
+ scan_to_h(s10)
325
386
 
326
387
  else
327
388
 
@@ -347,7 +408,7 @@ class Kvx
347
408
 
348
409
  else
349
410
 
350
- value, name = s.split(': ',2).reverse
411
+ value, name = s.split(/: */,2).reverse
351
412
  name ||= 'description'
352
413
  v = value =~ /^\{\s*\}$/ ? {} : value.to_s
353
414
 
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.2
4
+ version: 0.9.7
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-02-20 00:00:00.000000000 Z
38
+ date: 2021-05-19 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