line-tree 0.8.0 → 0.9.3

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: 7643a609c4195107cbf1d9f929e5f04ebadb33f4c2207faca858e62741ff7acc
4
- data.tar.gz: f620f7bdd66650d12f6b12b701068378ff52d12e8727bedda5fbdb56be3cf986
3
+ metadata.gz: a4941d5015036d351165b5d40866904d2808511e2aff6ae5fbfbc4d05f960ac9
4
+ data.tar.gz: 8169bc61faade352e4e7541e8edc4acf8e06a0f7cebc9fc833390a9106596faf
5
5
  SHA512:
6
- metadata.gz: ca0a85402197dfc65d2fc10af2caa01a3bba0b5b47356a824008c93e664a409f0edb010aeee61f329f23cf98729f46d45e74431bd6e7b4b9007182a68e94d52f
7
- data.tar.gz: '069e9fa9f845e35f9800e2abdb08141722bca51ed101d77c09c0f52f44fd190b8041d552acb0ec8f4cc36651f524d848a7d75a7fe23fce7cc2b5529458563c4c'
6
+ metadata.gz: 759dce7b2018ea6e914d94b3d3478b2d02e80cb62405d6624e6a3fa5cc81fa28feb2132d9f7e7c59bf85ec0efa66461f88a69980577ef4c02dcf807ff5b67517
7
+ data.tar.gz: 0d405fb0a21d367f6bd01fde12543f8ed163e54565c03845ba5751647eaeb536d989caa80d0f40e291ed47d9a6ac3cab42797bb506574a2fa3010852a1da868c
checksums.yaml.gz.sig CHANGED
@@ -1,5 +1,2 @@
1
- ����T>�Z��'��t�3pL5����Z�U�s�6cD�R A��Yy�
2
- -7���p�{h^h@6�~Kk����
3
- �������2U�����b'sF:б��r�Ie�HE�bEh>R� V=ǿ �[�֓�\�Z� ������3�*��0r�K|��=�[��o���{�D�-�F ��k'�Q���~N�r��’
4
- ���)BH��z=�;��F�*�{~Ǵ���� `��},S��09�R��5e��n�6�e ���[XqU���<H���j�q/�
5
- Xf|SNgm�PR�w
1
+ ��RY�
2
+ G���"�ΐh{��M���g��Ǫ8��+��ܠP�ˮƨ?�:�������<�uz��������O �����E��Š-�������/QN�eOi��yL���r6Q��;�� ��?l�����f�V# �b
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
 
@@ -28,7 +41,7 @@ class LineTree
28
41
 
29
42
  lines = ignore_blank_lines ? s.gsub(/^ *$\n/,'') : s
30
43
  puts ('lines : ' + lines.inspect).debug if @debug
31
- @to_a = scan_shift(lines.strip, level)
44
+ @to_a = scan_shift(lines.lstrip, level)
32
45
 
33
46
  end
34
47
 
@@ -53,6 +66,10 @@ class LineTree
53
66
 
54
67
  end
55
68
 
69
+ def to_h()
70
+ build_h(@to_a)
71
+ end
72
+
56
73
  def to_html(numbered: false)
57
74
 
58
75
  @numbered = numbered
@@ -62,6 +79,27 @@ class LineTree
62
79
  Rexle.new(s).xml declaration: false
63
80
 
64
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
65
103
 
66
104
  def to_xml(options={})
67
105
  to_doc.xml(options)
@@ -69,6 +107,24 @@ class LineTree
69
107
 
70
108
  private
71
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
+
72
128
  def encap(a)
73
129
 
74
130
  a.each do |node|
@@ -152,7 +208,7 @@ class LineTree
152
208
 
153
209
  puts 'x: ' + x.inspect if @debug
154
210
 
155
- x.sub!(/ *$/,'')
211
+ #jr240521 x.sub!(/ *$/,'')
156
212
 
157
213
  if @ignore_label == true or not x[/.*/][/^ *\w+:\S+/] then
158
214
 
@@ -204,17 +260,31 @@ class LineTree
204
260
 
205
261
  def scan_a(a)
206
262
 
207
- puts 'a: ' + a.inspect if @debug
263
+ puts 'a: ' + a.inspect if @debug
208
264
 
209
265
  a.each do |node|
210
-
211
- scan_a node[1..-1] if node[1..-1].is_a? Array
212
266
 
213
- if node.is_a? Array then
214
- r = parse_node(node[0])
215
- node[0] = r[0]; node.insert 1, r[1], r[2]
216
- 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]
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]
217
285
 
286
+ end
287
+ end
218
288
  end
219
289
 
220
290
  if a.first.is_a? String then
@@ -226,8 +296,8 @@ class LineTree
226
296
  return [nil,non_element] if non_element
227
297
  end
228
298
 
229
- r = parse_node(s)
230
- 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]
231
301
  end
232
302
 
233
303
  a
@@ -237,12 +307,9 @@ class LineTree
237
307
 
238
308
  def get_attributes(s)
239
309
 
240
- a = s.scan(/\w+: ["'][^"']+["']/).map do |attr|
241
-
242
- name, val = attr.match(/\s*([^:=]+)[:=]\s*['"]*\
243
- ([a-zA-Z0-9\(\);\-\/:\.,\s"'_\{\}\$]*)/).captures
244
- [name, val.sub(/['"]$/,'')]
245
- 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
246
313
 
247
314
  Hash[*a.flatten]
248
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.8.0
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwNjA5MTcxMDE4WhcN
15
- MjAwNjA4MTcxMDE4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC4AxCY
17
- XGf1ySV1wgjBLFG175tA+FRxhRXXGUv+pLAlzuW+JdCAS2/7mftnxDhsSWDOdbcL
18
- /NkJ6l4mpt7pPbDmRbPySbnsocyC/EXXrI6zK845Yz2iEwU55hBt6Io66KKQljMD
19
- B0dMK32UAIYrpMDISLiCCsbiHt2JeGoGao2V4oFK0JEv1SP2SRhQJwOSW3XYVibW
20
- alLzxQnRRurAmPvLb/OxdXEosgy9W8nJu4+saG0qkV5Jb0uffMBMTTyfoxMreQVq
21
- bOAYpcDZb2z6EFg5eirPCCBUaicen86xbV83ervKySxcmAAPm4hmk/QTLKEQWQIK
22
- E5jxkZpXyggQnLRow8pfs6ZrbrRuyB2jkvyccNRjU7AE+8mQcGEKI2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BMkobSNSJajZP1TPt48HmcYDMsYfdQzzF72
33
+ wgaSGvXwxq3FIPeFXk2yfUq7IOTIxHBH3q6ULVtW8NKnc5DckqUtfKbgflitRTd+
34
+ RtFCP/+DTXiYybQMXhdI3G/0MimLvIoEa7ytR5PvX86J+3abWenqiJ9+KXEqIroz
35
+ PR3ZcZkDNVXMAWJRegTgs3bTj/TOBz/9wA/ltrJjqU6xHPnNoEe/W5oSQtUywvAh
36
+ hWGDTAfEg/j8AdkfGnhBG1OK
37
37
  -----END CERTIFICATE-----
38
- date: 2019-06-09 00:00:00.000000000 Z
38
+ date: 2021-05-24 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '1.5'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.5.1
49
+ version: 1.5.11
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  version: '1.5'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.5.1
59
+ version: 1.5.11
60
60
  description: Line-tree parses indented lines of text and returns an array representing
61
61
  a tree structure.
62
- email: james@jamesrobertson.eu
62
+ email: digital.robertson@gmail.com
63
63
  executables: []
64
64
  extensions: []
65
65
  extra_rdoc_files: []
66
66
  files:
67
67
  - lib/line-tree.rb
68
- homepage: https://github.com/jrobertson/line-tree
68
+ homepage: http://github.com/jrobertson/line-tree
69
69
  licenses:
70
70
  - MIT
71
71
  metadata: {}
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.0.1
87
+ rubygems_version: 3.1.2
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: line-tree
metadata.gz.sig CHANGED
Binary file