line-tree 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d6c717f1207c926dec103d34b2ac20d9ebd6c9bca38129552e70e29ac842089
4
- data.tar.gz: a538960995601cbe45b227ba164930665cdadd0ca98177761066e0162f5ffa9a
3
+ metadata.gz: 9c851dd296720238d1bab5e87773fea3e7443c094113a496cf2f9029063cfb49
4
+ data.tar.gz: 7f63878999b0b4b6c6bfd7c5cead345caf850d1dcfb5e4130a3e865fbecc1cac
5
5
  SHA512:
6
- metadata.gz: 3c4eec204d400c1348e3ec70b5b541830a17058c374ae7de406f5346c7d80ce79482d73f113cc47e022b4dc9df936ab3f304b310ad3dfb5ca07b90a1654f07b5
7
- data.tar.gz: f9433a19dc0ba57cf40bc3db12d39fa5337e4ce8d603226a7d5065c3ee88ff3d4a318aa28629656a5cb06e153a419db46b8dedf34e14fa9029c5ba7e83934f30
6
+ metadata.gz: 49b75a3091fc00f633ba78a1a0fdb4413e0ee48ceb3b24ac1ba61d6a4f34ceb1927be408fedf4ab48b6db8b8c37eddf8deada81b7a94152909b836e1a5e570a7
7
+ data.tar.gz: 228e3a7034b8cc7d33a1b09c76b21e4498f4f819760203eb5bbcfa9f95ce63d249c144c4d7f47eaf4708c383661528fbb14a147e796142efa75eb0d8449a94d6
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/line-tree.rb CHANGED
@@ -20,8 +20,6 @@ end
20
20
 
21
21
  class LineTree
22
22
  using ColouredText
23
-
24
- attr_reader :to_a
25
23
 
26
24
  def initialize(raw_s, level: nil, ignore_non_element: true,
27
25
  ignore_blank_lines: true, ignore_label: false,
@@ -41,10 +39,14 @@ class LineTree
41
39
 
42
40
  lines = ignore_blank_lines ? s.gsub(/^ *$\n/,'') : s
43
41
  puts ('lines : ' + lines.inspect).debug if @debug
44
- @to_a = scan_shift(lines.strip, level)
42
+ @to_a = scan_shift(lines.lstrip, level)
45
43
 
46
44
  end
47
45
 
46
+ def to_a(normalize: false)
47
+ normalize ? norm(@to_a) : @to_a
48
+ end
49
+
48
50
  def to_doc(encapsulate: false)
49
51
 
50
52
  a = @to_a
@@ -79,6 +81,39 @@ class LineTree
79
81
  Rexle.new(s).xml declaration: false
80
82
 
81
83
  end
84
+
85
+ # key–value pair returns Hash object describing a
86
+ # flat representation of a tree
87
+ #
88
+ def to_kv_pair
89
+
90
+ def scan2keypair(h, trail=nil)
91
+
92
+ h.inject([]) do |r,x|
93
+
94
+ if x.last.is_a? String then
95
+
96
+ key, val = x
97
+
98
+ new_key = if r.last and r.last.first.length > 0 then
99
+ key.to_s
100
+ else
101
+ key.to_s
102
+ end
103
+ r << [[trail, new_key].compact.join('/'), val]
104
+ else
105
+ new_key = x.first.to_s
106
+ r << [new_key, x.last.first]
107
+ r.concat scan2keypair(x.last.last, [trail, new_key].compact.join('/'))
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+
114
+ scan2keypair(self.to_h).to_h
115
+
116
+ end
82
117
 
83
118
  def to_tree()
84
119
 
@@ -194,6 +229,30 @@ class LineTree
194
229
 
195
230
  end
196
231
 
232
+ # Improves readability by removing unnecessary brackets from an Array row.
233
+ # Thus making it a String when there are no children.
234
+ #
235
+ def norm(a)
236
+
237
+ a.map do |x|
238
+
239
+ if x.is_a? Array then
240
+
241
+ if x.length < 2 then
242
+ x.first
243
+ else
244
+ row = norm(x[1..-1])
245
+ [x.first, row]
246
+ end
247
+
248
+ else
249
+ x
250
+ end
251
+
252
+ end
253
+ end
254
+
255
+
197
256
 
198
257
  def scan_shift(lines, level=nil)
199
258
 
@@ -208,7 +267,7 @@ class LineTree
208
267
 
209
268
  puts 'x: ' + x.inspect if @debug
210
269
 
211
- x.sub!(/ *$/,'')
270
+ #jr240521 x.sub!(/ *$/,'')
212
271
 
213
272
  if @ignore_label == true or not x[/.*/][/^ *\w+:\S+/] then
214
273
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,32 +10,33 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwNTAyMDEyNTIzWhcN
15
- MjEwNTAyMDEyNTIzWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDeefOB
17
- XvRYlF86o1HH1xFCsA3T3Zw9YRZB2XnefFtfUJzhac7MXgioL88mMWijdsZ+jkbU
18
- cChj3JA71hR84u8qMhIU8fBFGZsTdGiK2AR+FbuQGlATdpagyFH6H9qrGneICIjm
19
- JEKoJsukwsce+QJBroPzahHjI+RtU9sZ3Fv66FO4+gYvKC+VyqJZMR+VioaZ1UDd
20
- GDJ0ryGuJUiRLS377299caPyhRHESz1knlXxTFqgPatOP63henIg9Vcfscdw1sRG
21
- umj7CGTB6mRgnBTUrkGQBbh/X1KvVFxy8REfwXHd7XSqxZ5xX+N/hGB2KijeDyGa
22
- J8OARoeZIr9ZCWlj+vTbMtediJqghiX3XLh7Z7zDYIFZlCVWCzubLifMi0T46TOM
23
- 6bKk+DqUiXok8yzpTw/6ejI7wtcCuaR4BM2eAkzgm0qQsjsqndaKEbV6vN+jJn4/
24
- wkLvkwKyRyXuASg8RinC6soJ84o/MYoDAdchEnfXIagwNLg35WSxbOJGsmkCAwEA
25
- AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUOB2r9N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OsS5CkdzcDjY0xYzMbnyJ1PakT45P03bQE3vo3uvrp0
34
+ VAkB38cUXGgk86qi7RozTrJgr8bMkrjdlAgDiiHLMJ0K0oIkf5cadgarYvbmQ1nX
35
+ iXjhjSXYck8mrCCYrsDy9Cz/WCR/LmuOCn0QwL4VMDyfeaozAFME/rO5jNCPPOvg
36
+ C5EdQTQBDv+/PxpfNRw9c/rDC44+fVecf9eUtJtfP2oliL7q8SlpE2Bt9D1H/ePQ
37
+ diGSVRnIxA91BeBOGkt0dmzMPFRHD4+TvtM=
37
38
  -----END CERTIFICATE-----
38
- date: 2021-04-07 00:00:00.000000000 Z
39
+ date: 2022-09-19 00:00:00.000000000 Z
39
40
  dependencies:
40
41
  - !ruby/object:Gem::Dependency
41
42
  name: rexle
@@ -46,7 +47,7 @@ dependencies:
46
47
  version: '1.5'
47
48
  - - ">="
48
49
  - !ruby/object:Gem::Version
49
- version: 1.5.11
50
+ version: 1.5.14
50
51
  type: :runtime
51
52
  prerelease: false
52
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,7 +57,7 @@ dependencies:
56
57
  version: '1.5'
57
58
  - - ">="
58
59
  - !ruby/object:Gem::Version
59
- version: 1.5.11
60
+ version: 1.5.14
60
61
  description: Line-tree parses indented lines of text and returns an array representing
61
62
  a tree structure.
62
63
  email: digital.robertson@gmail.com
@@ -84,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  requirements: []
87
- rubyforge_project:
88
- rubygems_version: 2.7.10
88
+ rubygems_version: 3.3.7
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: line-tree
metadata.gz.sig CHANGED
Binary file