xml_col_finder 0.1.1 → 0.2.0

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: 45d703949948a3a22ed318a5297cf621eecd664e842ac1f654c497018e4b9ec1
4
- data.tar.gz: f46900d22268f63f35e525bdc70156e0cf9bf68da7faf292facbe682c9094bc8
3
+ metadata.gz: f197d3b4951b9482ecc356421fb1d665b3e2e33a4e0d0ca1fb91da463877e690
4
+ data.tar.gz: d3c4e36b690c2684b9bd8ace2dbe1057fd89deaefaa402dcbbb77524cb82d693
5
5
  SHA512:
6
- metadata.gz: c5da937ee341a1b26a587113633c51912c7f61f7409eebd0197c241860c799c266be394ed247009cbb6158cf4ca5f3de45ed4a46380b49736d25cecf86828f52
7
- data.tar.gz: 2bfc5dee7af91f61327d71fafe91a73ea0e6060e8953dd193e6a9e1b6f839db9a0d33574cc3bb76f2c42824817e47d135edd866b1fb76108496c50d8ce4f7366
6
+ metadata.gz: 38a8eaf60f976d7773e7d611e240e0ace91dc487bb06f47950915ae96dc26d289878ec62a62d8ab7dd5fab0cde15d7a9dda3dd97a2dc567185c86572eaa76289
7
+ data.tar.gz: cd4b309ae655a17efb48818f44004753f957a28e5cdbae462d1f31ab3bb97f4ccaf306408c0276b6df1d547e7ebf37a90ce55bcb04313ac5abbe0a8a0cfeadac
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- ^}f{�\�|ؽ$ �X8���,Pz��Ǧ�!�H��W�  ��Og �6��)�1,��|Ԃ�D�B��Sl裱�e nODo��D|���,�ɶd��M�q��9�S_�$󗜞��ah��b�mt�6NR3b҈T)�؅�ӏOCQ %���pHS��$�:�l�C��U*Ư�OT�! n,4��߇�<�)�һ)��~ˇ<Us��O B��ƫ'�`��u ��B��/0 3�w���8���%=����{�Q����
2
- fG�U��: R�x�qA�^q ��gP��)&�:��bL�Q����0��"=cYݐ]v��biwS���ظ�:�e�-�sZ ���5w�s1�SV������̥х�Z�4ۯ�Ͱ�L
1
+ !~��WXɿٷWI����Q����Vn�.Qf�-�v?�ڝ�S���TU�&6<��ŭ�D�g�����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?@�
@@ -30,8 +30,54 @@ class XMLColFinder
30
30
 
31
31
  end
32
32
 
33
+ def to_code()
34
+
35
+ @tags = {}
36
+ xpath, remaining = @to_a
37
+
38
+ eid = getid(xpath)
39
+ linex = formatline('doc', eid, xpath)
40
+ a = scan(remaining, eid)
41
+
42
+ a.flatten.compact.prepend linex
43
+
44
+ end
45
+
33
46
  private
34
47
 
48
+ def formatline(pid, eid=nil, key=nil, tail=nil)
49
+
50
+ if eid then
51
+ line = "%s = %s.element(\"%s\")" % [eid, pid, key]
52
+ line += '.text' if tail.is_a? String
53
+ else
54
+ line = "%s.text" % pid
55
+ end
56
+
57
+ return line
58
+ end
59
+
60
+
61
+ def getid(rawtag)
62
+
63
+ rawtagx = rawtag.split('/').last[/\w+/]
64
+
65
+ tag = case rawtagx.to_sym
66
+ when :a
67
+ 'link'
68
+ else
69
+ rawtagx
70
+ end
71
+
72
+ if @tags.include?(tag) then
73
+ @tags[tag] =~ /\d+$/ ? @tags[tag].succ! : @tags[tag] += '1'
74
+ else
75
+ @tags[tag] = tag
76
+ end
77
+
78
+ end
79
+
80
+
35
81
  # Groups xpath by matching branches
36
82
  #
37
83
  def group_by_xpath(a)
@@ -99,6 +145,41 @@ class XMLColFinder
99
145
 
100
146
  end
101
147
 
148
+ def scan(a, eid='doc', pid=eid.clone)
149
+
150
+ a.map do |row|
151
+
152
+ head, tail = row
153
+
154
+ if head.is_a? Array then
155
+
156
+ hline = scan(row, eid, pid)
157
+
158
+ elsif head
159
+
160
+ if head[0] == '/' then
161
+
162
+ key = head[1..-1]
163
+
164
+ eid = getid(key)
165
+ hline = formatline(pid, eid, key, tail)
166
+
167
+ else
168
+
169
+ hline = formatline(pid=eid)
170
+ end
171
+ end
172
+
173
+ if tail.is_a? Array then
174
+ tline = scan(tail, eid)
175
+ end
176
+
177
+ [hline, tline]
178
+ end
179
+
180
+ end
181
+
182
+
102
183
  def truncate_xpath(records, offset=0)
103
184
 
104
185
  records.map do |record|
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file