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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28d3eefa7cd6ef96db0e76506712da6ed70b6e03
4
- data.tar.gz: 9afbfc0f86842b714a6f066394efd551e6449ca1
3
+ metadata.gz: a24ef9a39fa0ffed57fb910ea8476403d11739c9
4
+ data.tar.gz: f1d165c398d4e3147b370653d1ed16db74f48051
5
5
  SHA512:
6
- metadata.gz: 6e1c2ebf332cea5a86be5f92824ec6d8385bd7cc64896e812d65d06c7a63bdce6d0ca1682dd30ea352f5ae73ed6807474d5973629854c1677f6e8e01fb4857e7
7
- data.tar.gz: e51187dd8b5bbf6cbad06db2f2e3afffabccf80b24e780749f56ceedce8706583f85f77a1a712b0f7c07e1cc204a0efff1453f6e0f1eb136ecfaa4cc5dd0465c
6
+ metadata.gz: f79566d9b4a1cc10fb0b33c2e9b57ddefd9113977d321f2f42fde1ca5002880a45d0e70beb2603f51f04f4354878300d42a27f3bb7eb5c72fff1ec0f3e7a1c65
7
+ data.tar.gz: d9a0d16c41059dedd7f8c859c8a79cf4d53e80ca2557b907d26be42097b3ae860939dc4dab38b1b7e88cb1867c23122804857f42fad165aafab426e7dc1bb1e6
checksums.yaml.gz.sig CHANGED
@@ -1,4 +1 @@
1
- j5\r����)�u� ��������̢��["8}RsaE =jU��wڕ������N
2
- � e��|��XiF�(
3
- a-�
4
- g��|9�r`:mw7����*ħ<�φ�JHW;��C�s�z��/z4�: oQg�˼i�b�&^'���TZ�?��<2w
1
+ 90=�����5/����"86caF�uo>���Z�#�f5RI��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"Wq; �ʌ[M!�=_��!���M) A�5G���G ��.MEM@�5��dc���C,�$
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- P}�5r� �|�s�gө��vR;��D�R�^eAK���x�٭�l�a�(��g�M�T�jm�T��4�:5w`�D{����y�0z�ދɛ�
2
- &?j����� 0R]yXs��B=�l�����g{� >\�+��"��I��?��>!'�d�Ӓ��WHo�z̎���"1Ә�?�3wjF�$s'·JN���Og+�N9���)�@ô�Z��\�;'h�+��%Cܡ���~+�#S����2s�j�8���
1
+ ��p}k0XV��;�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.16
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-18 00:00:00.000000000 Z
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