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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f61074cf688e2b8575f49e7b90ce4b01eaa999814427cb31814b9ce7349d790c
4
- data.tar.gz: 243c42bb0f38ea3997d72060fa96da11b7bf00067d02cff35db1b44d1923de5c
3
+ metadata.gz: 2d6c717f1207c926dec103d34b2ac20d9ebd6c9bca38129552e70e29ac842089
4
+ data.tar.gz: a538960995601cbe45b227ba164930665cdadd0ca98177761066e0162f5ffa9a
5
5
  SHA512:
6
- metadata.gz: b4e91fb43f1b8b94cf6c4f352f1171cbe31bd75533a02abeefcfd6f75c8fd0ab5acb3bde9c12932ee56834abcf25443417104535b26096db97d318e85c639f11
7
- data.tar.gz: '0688401ae1e49f4ccb8dfc04337b31a0cacfad3ba2f00231959ad95b85ee057e78b1e9dfc653554a78d537c71b8abdf38ff83e234de91c92ae6e767adf911628'
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
- s = root ? root + "\n" + raw_s.lines.map {|x| ' ' + x}.join : raw_s
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
- Rexle.new(a2)
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
- if node.is_a? Array then
208
- r = parse_node(node[0])
209
- node[0] = r[0]; node.insert 1, r[1], r[2]
210
- end
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
- r = parse_node(s)
224
- a[0] = r[0]; a.insert 1, r[1], r[2]
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.scan(/\w+: ["'][^"']+["']/).map do |attr|
235
-
236
- name, val = attr.match(/\s*([^:=]+)[:=]\s*['"]*\
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.7.2
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
- MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwMzE1MjIwMTUyWhcN
15
- MTkwMzE1MjIwMTUyWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDwIZho
17
- j0m/X3SfsXMs+3Tw2LkqdNVDegCd22MEe9vTWYsQg5lnMrePYiDjWQQnM82Udvr9
18
- K2oCsPkJC6QLQRTUO+zr0Bh0nJ7gNi8SxZyGzG2lgzjVAVG3bLWCPwoCWUimoyNO
19
- e6tRe5xnSC5kJnnT9PJQ7zC/ojbJrbzoQOmEEu7qrG7VHJ0XELWDg89B+khJS8cl
20
- 2nsjOimG3enalb6bATOwCrmaJk0jOJRSr6tyIMvy9imnKgo2Rz2dtXJoAaT0pl7W
21
- RfpuVfqp2xCzrJK2tF5lSHlzyH49IpD6a9Gpyj90Fg8YnIuZXovedBhd9zyUn1rV
22
- OlrRnOwDqK/Gw9K7AgMBAAGjgYowgYcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
23
- HQYDVR0OBBYEFHv+A4lqesPYu1Art+YRueCuknKuMCYGA1UdEQQfMB2BG2dlbW1h
24
- c3RlckBqYW1lc3JvYmVydHNvbi5ldTAmBgNVHRIEHzAdgRtnZW1tYXN0ZXJAamFt
25
- ZXNyb2JlcnRzb24uZXUwDQYJKoZIhvcNAQEFBQADggEBAJDE/cZXxbtNL3kdBI/s
26
- 1mf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qQsjsqndaKEbV6vN+jJn4/
24
+ wkLvkwKyRyXuASg8RinC6soJ84o/MYoDAdchEnfXIagwNLg35WSxbOJGsmkCAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUOB2r9N+h
26
+ gG6rn2ttGp3RVDUu+8cwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEA1caJWb6DWlELBPufoEWz5MD5c/4YRrPXFbaxcR9F
29
+ 6FVeM0/U+RxfL21LSiEM1d/LSp59szaQLNu5//kzU7BnRiloKJZnTxG42imdLdDf
30
+ eOvJ8bpHzHv14YaxG/odQ3m6lXgsoAyh4EQyhc0B838xE9LxFiRjV4DNaLIdL9xB
31
+ xx3ahpqugp3KziLAiSbh5ljRrVS3ShPsZ1b+vIpCJOCsPiIkcMNWso8+uXLEfi0i
32
+ TLrLGtJycaUfRUpn+9jKGj3yBIb2pxb2BiCFG9/yJM0zTtcRw8UueOXIahZPPUMV
33
+ p+bGmxywlIxSYxGMVc2nrC4Vq+n3VH3Zu9N7vi7PwVuL7KI+Y0eGaBwxC/k5cgUq
34
+ nGvja9yjtlc3kAD5ttXyrCj4eg9wObSc/Jiy3C0m46c6QYu+C5bLynmEXBJT00Zy
35
+ 4ILlu3I+eftJ4QWM2f5lx0ZsEAgVLvw36qPDrdyX8EZf7jWgEBa1DGyDULuKoXbg
36
+ mL1f4imWp1K3Hh2L8I7XFMbY
32
37
  -----END CERTIFICATE-----
33
- date: 2018-12-18 00:00:00.000000000 Z
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.0
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.0
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: james@r0bertson.co.uk
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: https://github.com/jrobertson/line-tree
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.6
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