lineparser 0.1.16 → 0.1.17
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -4
- data.tar.gz.sig +2 -2
- data/lib/lineparser.rb +58 -2
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a24ef9a39fa0ffed57fb910ea8476403d11739c9
|
4
|
+
data.tar.gz: f1d165c398d4e3147b370653d1ed16db74f48051
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f79566d9b4a1cc10fb0b33c2e9b57ddefd9113977d321f2f42fde1ca5002880a45d0e70beb2603f51f04f4354878300d42a27f3bb7eb5c72fff1ec0f3e7a1c65
|
7
|
+
data.tar.gz: d9a0d16c41059dedd7f8c859c8a79cf4d53e80ca2557b907d26be42097b3ae860939dc4dab38b1b7e88cb1867c23122804857f42fad165aafab426e7dc1bb1e6
|
checksums.yaml.gz.sig
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
|
2
|
-
�e��|��XiF�(
|
3
|
-
a-�
|
4
|
-
g��|9�r`:mw7����*ħ<�φ�JHW;��C�s�z��/z4�:oQg�˼i�b�&^'���TZ�?��<2w
|
1
|
+
90=�����5/����"86ca�F�uo>���Z�#�f�5RI��C�OK�L��)hB��Sx���_���:��c�R��4@��v�=�'��ͫ��~K�6�Fn�Ώ�*�(�.� 1TR� ^�H�k` SRq�к23�-Z8DU�d��|�g��k�7�ף����@qx��Y�!-�d�4�\x�X"W�q; �ʌ[M!�=_��!���M)A�5G���G ��.MEM@�5��d�c���C,�$
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
��p}k0�XV��;�9�ژ�@�;'�� (z���)�\�ߦ�2P8���e'�`�4
|
2
|
+
�<�kz�7���;I�=�x@{|@Ǯ!:!˲�7J���h���ha��b�&�_�i禃�q-��[`�G�8G0o+���G�t�]�D9�*�Bm�D"u{����_�hs���.Z���[�:�{ ��Z�J��
|
data/lib/lineparser.rb
CHANGED
@@ -7,9 +7,9 @@ require 'line-tree'
|
|
7
7
|
|
8
8
|
class LineParser
|
9
9
|
|
10
|
-
def initialize(patterns=[], lines=nil, ignore_blank_lines: true)
|
10
|
+
def initialize(patterns=[], lines=nil, ignore_blank_lines: true, debug: true)
|
11
11
|
|
12
|
-
@ibl = ignore_blank_lines
|
12
|
+
@ibl, @debug = ignore_blank_lines, debug
|
13
13
|
@h = {
|
14
14
|
|
15
15
|
String: lambda do |s, pattern|
|
@@ -51,18 +51,74 @@ class LineParser
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def parse(s)
|
54
|
+
|
54
55
|
@a = scan @tree_patterns, LineTree.new(s, ignore_blank_lines: @ibl).to_a
|
56
|
+
@h = build_hash @a
|
57
|
+
@a
|
58
|
+
|
55
59
|
end
|
56
60
|
|
57
61
|
def to_a
|
58
62
|
@a
|
59
63
|
end
|
64
|
+
|
65
|
+
def to_h()
|
66
|
+
@h
|
67
|
+
end
|
60
68
|
|
61
69
|
def to_xml
|
62
70
|
Rexle.new(xmlize(@a).inject([:root, '', {}]){|r,x| r << x}).xml if @a
|
63
71
|
end
|
64
72
|
|
65
73
|
private
|
74
|
+
|
75
|
+
|
76
|
+
def build_hash(a)
|
77
|
+
|
78
|
+
def filter(h2)
|
79
|
+
|
80
|
+
h = {}
|
81
|
+
puts 'h2: ' + h2.inspect if @debug
|
82
|
+
|
83
|
+
h2.each do |k, v|
|
84
|
+
|
85
|
+
puts 'v:' + v.inspect if @debug
|
86
|
+
|
87
|
+
h[k] = v.flat_map do |row|
|
88
|
+
|
89
|
+
a2 = []
|
90
|
+
|
91
|
+
if row[3] and row[3].any? then
|
92
|
+
|
93
|
+
puts 'row[3][0][1]: ' + row[3][0][1].inspect if @debug
|
94
|
+
|
95
|
+
if row[3][0][1].has_key? :captures then
|
96
|
+
|
97
|
+
a2 = row[3].map {|x| x[2].first }
|
98
|
+
|
99
|
+
else
|
100
|
+
a2 = filter(row[3].group_by {|x| x.first })
|
101
|
+
end
|
102
|
+
|
103
|
+
else
|
104
|
+
a2 = row[1].values.first
|
105
|
+
end
|
106
|
+
|
107
|
+
key = row[1].values.first
|
108
|
+
(key.empty? or key == a2) ? a2 : {key => a2}
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
return h
|
115
|
+
end
|
116
|
+
|
117
|
+
h3 = a.group_by {|x| x.first }
|
118
|
+
|
119
|
+
filter(h3)
|
120
|
+
|
121
|
+
end
|
66
122
|
|
67
123
|
def join(lines, indent='')
|
68
124
|
lines.map do |x|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lineparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
7CkP6/pzsGLnyfCNF6rkXny4G0mjMmALczbazUUCil4IJNYfvW28Nlm2cD1N6Y/t
|
31
31
|
Uck=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2018-06-
|
33
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: line-tree
|
metadata.gz.sig
CHANGED
Binary file
|