xml_col_finder 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: f197d3b4951b9482ecc356421fb1d665b3e2e33a4e0d0ca1fb91da463877e690
4
- data.tar.gz: d3c4e36b690c2684b9bd8ace2dbe1057fd89deaefaa402dcbbb77524cb82d693
3
+ metadata.gz: fb9968f62dfa167170d225305499a06a3fb07949d22b44cfc5fc7aaff2250e70
4
+ data.tar.gz: 590549966bf32070036e68f45ff1c61cc5b81b7c11a5237466928e573758eeb5
5
5
  SHA512:
6
- metadata.gz: 38a8eaf60f976d7773e7d611e240e0ace91dc487bb06f47950915ae96dc26d289878ec62a62d8ab7dd5fab0cde15d7a9dda3dd97a2dc567185c86572eaa76289
7
- data.tar.gz: cd4b309ae655a17efb48818f44004753f957a28e5cdbae462d1f31ab3bb97f4ccaf306408c0276b6df1d547e7ebf37a90ce55bcb04313ac5abbe0a8a0cfeadac
6
+ metadata.gz: a022f1836170e5628062360a2bef7d4fc26ac1748dd7970fd56eb76ca5fa194f2f61b75bf7f8dfe667191ef194aeb2306a8c5e94e55552aafa105e0d34a7828b
7
+ data.tar.gz: 2f932bcffe0ace2bfc4fdefb3df0fde1cff61e3095110fb765de6732c096c44066e13046591c8423bb75465e9b981774751c225b9791a72601bac97bb24237a5
checksums.yaml.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- !~��WXɿٷWI����Q����Vn�.Qf�-�v?�ڝ�S���T�U�&6<��ŭ�Dg�����j��Om��}�ԛ!�� ֐����6� C������
2
- ���ÖO�n�����؆�mHpl���HY�:.ɇ��z��(-�����E]��pT_�Iڜ"W�Z�������t�ٗf
3
- ���u�;����a�v[):����C��ujnz���d���D {9�FX�9�d��lgN��j?@�
1
+ T�V�c.nf���}�"Ny�S�dVA$�t/�n����F��*�2ay� .�7��"�L�B�ϊ#[����|��R�iQ��L�2���~�T�u� �N�6r]�u[��$�4�"����ے��i���jxe8W*%rT�!mf��\�QӪ�+i5�3G�*t�*�ԡ9�;�u��:�u����Aj�IG�8���U*����i9*��rΥ����dJG��,
2
+ d����Dn��F�*
@@ -33,6 +33,7 @@ class XMLColFinder
33
33
  def to_code()
34
34
 
35
35
  @tags = {}
36
+
36
37
  xpath, remaining = @to_a
37
38
 
38
39
  eid = getid(xpath)
@@ -45,13 +46,13 @@ class XMLColFinder
45
46
 
46
47
  private
47
48
 
48
- def formatline(pid, eid=nil, key=nil, tail=nil)
49
+ def formatline(pid, eid=nil, key=nil, tail=nil, index: nil)
49
50
 
50
51
  if eid then
51
52
  line = "%s = %s.element(\"%s\")" % [eid, pid, key]
52
53
  line += '.text' if tail.is_a? String
53
54
  else
54
- line = "%s.text" % pid
55
+ line = index ? ("%s[%d].text" % [pid, index]) : ("%s.text" % pid)
55
56
  end
56
57
 
57
58
  return line
@@ -119,8 +120,6 @@ class XMLColFinder
119
120
 
120
121
  else
121
122
 
122
- puts "path.join('/'): " + path.join('/').inspect
123
- puts 'txt:' + txt.inspect
124
123
 
125
124
  h2[stickypath.sub(/^\//,'')] ||= []
126
125
  h2[stickypath.sub(/^\//,'')] << [path.join('/'), txt]
@@ -147,6 +146,8 @@ class XMLColFinder
147
146
 
148
147
  def scan(a, eid='doc', pid=eid.clone)
149
148
 
149
+ #puts 'a: ' + a.inspect if @debug
150
+
150
151
  a.map do |row|
151
152
 
152
153
  head, tail = row
@@ -160,9 +161,17 @@ class XMLColFinder
160
161
  if head[0] == '/' then
161
162
 
162
163
  key = head[1..-1]
164
+ puts 'key: ' + key.inspect if @debug
163
165
 
164
166
  eid = getid(key)
165
- hline = formatline(pid, eid, key, tail)
167
+
168
+ hline = if tail.is_a? Array and tail.all? {|x| x.is_a? String } then
169
+ @prev_xpath = true
170
+ "%s = %s.xpath(\"%s\")" % [eid, pid, key]
171
+ else
172
+ @prev_xpath = false
173
+ formatline(pid, eid, key, tail)
174
+ end
166
175
 
167
176
  else
168
177
 
@@ -171,7 +180,20 @@ class XMLColFinder
171
180
  end
172
181
 
173
182
  if tail.is_a? Array then
174
- tline = scan(tail, eid)
183
+
184
+ if tail.compact[0].is_a? Array then
185
+
186
+ puts 'tail: ' + tail.inspect if @debug
187
+
188
+ tline = scan(tail, eid)
189
+
190
+ elsif tail.all? {|x| x.is_a? String} and tail[0][0] != '/'
191
+ puts '_tail: ' + tail.inspect if @debug
192
+ tline = tail.map.with_index do |x,i|
193
+ formatline(pid=eid, index: i)
194
+ end.join("\n")
195
+
196
+ end
175
197
  end
176
198
 
177
199
  [hline, tline]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml_col_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file