line-tree 0.7.2 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/line-tree.rb +92 -19
- metadata +31 -26
- 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: 2d6c717f1207c926dec103d34b2ac20d9ebd6c9bca38129552e70e29ac842089
|
4
|
+
data.tar.gz: a538960995601cbe45b227ba164930665cdadd0ca98177761066e0162f5ffa9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c4eec204d400c1348e3ec70b5b541830a17058c374ae7de406f5346c7d80ce79482d73f113cc47e022b4dc9df936ab3f304b310ad3dfb5ca07b90a1654f07b5
|
7
|
+
data.tar.gz: f9433a19dc0ba57cf40bc3db12d39fa5337e4ce8d603226a7d5065c3ee88ff3d4a318aa28629656a5cb06e153a419db46b8dedf34e14fa9029c5ba7e83934f30
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/line-tree.rb
CHANGED
@@ -5,6 +5,19 @@
|
|
5
5
|
require 'rexle'
|
6
6
|
|
7
7
|
|
8
|
+
module HashDigx
|
9
|
+
refine Hash do
|
10
|
+
|
11
|
+
def digx( a)
|
12
|
+
|
13
|
+
self.dig a[0], *a[1..-1].flat_map {|x| [:body, x]}
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
8
21
|
class LineTree
|
9
22
|
using ColouredText
|
10
23
|
|
@@ -14,8 +27,11 @@ class LineTree
|
|
14
27
|
ignore_blank_lines: true, ignore_label: false,
|
15
28
|
ignore_newline: true, root: nil, debug: false)
|
16
29
|
|
30
|
+
|
17
31
|
puts 'inside linetree'.info if @debug
|
18
|
-
|
32
|
+
|
33
|
+
@root = root
|
34
|
+
s = raw_s
|
19
35
|
|
20
36
|
@ignore_non_element = ignore_non_element
|
21
37
|
@ignore_label = ignore_label
|
@@ -39,14 +55,21 @@ class LineTree
|
|
39
55
|
puts 'before scan_a' if @debug
|
40
56
|
scan_a(*a)
|
41
57
|
end
|
58
|
+
|
42
59
|
|
43
|
-
a2.unshift('root', {})
|
44
|
-
puts 'a2: ' + a2.inspect if @debug
|
45
60
|
|
46
|
-
|
61
|
+
a3 = @root ? a2.unshift(@root, {}) : a2.flatten(1)
|
62
|
+
|
63
|
+
puts 'a3: ' + a3.inspect if @debug
|
64
|
+
|
65
|
+
Rexle.new(a3)
|
47
66
|
|
48
67
|
end
|
49
68
|
|
69
|
+
def to_h()
|
70
|
+
build_h(@to_a)
|
71
|
+
end
|
72
|
+
|
50
73
|
def to_html(numbered: false)
|
51
74
|
|
52
75
|
@numbered = numbered
|
@@ -56,6 +79,27 @@ class LineTree
|
|
56
79
|
Rexle.new(s).xml declaration: false
|
57
80
|
|
58
81
|
end
|
82
|
+
|
83
|
+
def to_tree()
|
84
|
+
|
85
|
+
def make_tree_list(a)
|
86
|
+
|
87
|
+
items = a.inject([]) do |r,x|
|
88
|
+
|
89
|
+
if x.is_a? Array then
|
90
|
+
r << make_tree_list(x)
|
91
|
+
else
|
92
|
+
r + ['item', {title: x}]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
a = make_tree_list(@to_a)
|
99
|
+
doc = Rexle.new(['tree', {}, *a])
|
100
|
+
doc.xml
|
101
|
+
|
102
|
+
end
|
59
103
|
|
60
104
|
def to_xml(options={})
|
61
105
|
to_doc.xml(options)
|
@@ -63,6 +107,24 @@ class LineTree
|
|
63
107
|
|
64
108
|
private
|
65
109
|
|
110
|
+
def build_h(a)
|
111
|
+
|
112
|
+
a.inject({}) do |r,x|
|
113
|
+
|
114
|
+
h2 = if x.is_a? Array and x.length > 1 then
|
115
|
+
|
116
|
+
{x[0] => {summary: {}, body: build_h(x[1..-1]) } }
|
117
|
+
|
118
|
+
else
|
119
|
+
|
120
|
+
{x[0] => {summary: {}}}
|
121
|
+
end
|
122
|
+
|
123
|
+
r.merge(h2)
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
66
128
|
def encap(a)
|
67
129
|
|
68
130
|
a.each do |node|
|
@@ -198,17 +260,31 @@ class LineTree
|
|
198
260
|
|
199
261
|
def scan_a(a)
|
200
262
|
|
201
|
-
puts 'a: ' + a.inspect if @debug
|
263
|
+
puts 'a: ' + a.inspect if @debug
|
202
264
|
|
203
265
|
a.each do |node|
|
204
|
-
|
205
|
-
scan_a node[1..-1] if node[1..-1].is_a? Array
|
206
266
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
267
|
+
puts 'node: ' + node.inspect if @debug
|
268
|
+
|
269
|
+
if node.is_a? Array then
|
270
|
+
if node[1].is_a?(Array) and node[1][0] =~ /^<\w+/ then
|
271
|
+
|
272
|
+
r = parse_node(node[0])
|
273
|
+
node[0] = r[0]
|
274
|
+
node[2] = node[1][0]
|
275
|
+
node[1] = r[1]
|
211
276
|
|
277
|
+
else
|
278
|
+
|
279
|
+
scan_a node[1..-1] if node[1..-1].is_a?(Array)
|
280
|
+
|
281
|
+
puts 'node2: ' + node.inspect if @debug
|
282
|
+
|
283
|
+
r = parse_node(node[0])
|
284
|
+
node[0] = r[0]; node.insert 1, r[1], r[2]
|
285
|
+
|
286
|
+
end
|
287
|
+
end
|
212
288
|
end
|
213
289
|
|
214
290
|
if a.first.is_a? String then
|
@@ -220,8 +296,8 @@ class LineTree
|
|
220
296
|
return [nil,non_element] if non_element
|
221
297
|
end
|
222
298
|
|
223
|
-
|
224
|
-
|
299
|
+
r = parse_node(s)
|
300
|
+
a[0] = r[0]; a.insert 1, r[1], r[2]
|
225
301
|
end
|
226
302
|
|
227
303
|
a
|
@@ -231,12 +307,9 @@ class LineTree
|
|
231
307
|
|
232
308
|
def get_attributes(s)
|
233
309
|
|
234
|
-
a = s.
|
235
|
-
|
236
|
-
|
237
|
-
([a-zA-Z0-9\(\);\-\/:\.,\s"'_\{\}\$]*)/).captures
|
238
|
-
[name, val.sub(/['"]$/,'')]
|
239
|
-
end
|
310
|
+
a = s[1..-2].split(/(\w+:)/)[1..-1].each_slice(2).map do |label, val|
|
311
|
+
[label[0..-2], val.strip.sub(/^['"]/,'').sub(/['"]$/,'')]
|
312
|
+
end
|
240
313
|
|
241
314
|
Hash[*a.flatten]
|
242
315
|
end
|
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.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,27 +10,32 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwNTAyMDEyNTIzWhcN
|
15
|
+
MjEwNTAyMDEyNTIzWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDeefOB
|
17
|
+
XvRYlF86o1HH1xFCsA3T3Zw9YRZB2XnefFtfUJzhac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Ib2pxb2BiCFG9/yJM0zTtcRw8UueOXIahZPPUMV
|
33
|
+
p+bGmxywlIxSYxGMVc2nrC4Vq+n3VH3Zu9N7vi7PwVuL7KI+Y0eGaBwxC/k5cgUq
|
34
|
+
nGvja9yjtlc3kAD5ttXyrCj4eg9wObSc/Jiy3C0m46c6QYu+C5bLynmEXBJT00Zy
|
35
|
+
4ILlu3I+eftJ4QWM2f5lx0ZsEAgVLvw36qPDrdyX8EZf7jWgEBa1DGyDULuKoXbg
|
36
|
+
mL1f4imWp1K3Hh2L8I7XFMbY
|
32
37
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
38
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
34
39
|
dependencies:
|
35
40
|
- !ruby/object:Gem::Dependency
|
36
41
|
name: rexle
|
@@ -41,7 +46,7 @@ dependencies:
|
|
41
46
|
version: '1.5'
|
42
47
|
- - ">="
|
43
48
|
- !ruby/object:Gem::Version
|
44
|
-
version: 1.5.
|
49
|
+
version: 1.5.11
|
45
50
|
type: :runtime
|
46
51
|
prerelease: false
|
47
52
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -51,16 +56,16 @@ dependencies:
|
|
51
56
|
version: '1.5'
|
52
57
|
- - ">="
|
53
58
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.5.
|
59
|
+
version: 1.5.11
|
55
60
|
description: Line-tree parses indented lines of text and returns an array representing
|
56
61
|
a tree structure.
|
57
|
-
email:
|
62
|
+
email: digital.robertson@gmail.com
|
58
63
|
executables: []
|
59
64
|
extensions: []
|
60
65
|
extra_rdoc_files: []
|
61
66
|
files:
|
62
67
|
- lib/line-tree.rb
|
63
|
-
homepage:
|
68
|
+
homepage: http://github.com/jrobertson/line-tree
|
64
69
|
licenses:
|
65
70
|
- MIT
|
66
71
|
metadata: {}
|
@@ -80,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
85
|
version: '0'
|
81
86
|
requirements: []
|
82
87
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.7.
|
88
|
+
rubygems_version: 2.7.10
|
84
89
|
signing_key:
|
85
90
|
specification_version: 4
|
86
91
|
summary: line-tree
|
metadata.gz.sig
CHANGED
Binary file
|