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 +4 -4
- checksums.yaml.gz.sig +3 -2
- data/lib/xml_col_finder.rb +81 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f197d3b4951b9482ecc356421fb1d665b3e2e33a4e0d0ca1fb91da463877e690
|
4
|
+
data.tar.gz: d3c4e36b690c2684b9bd8ace2dbe1057fd89deaefaa402dcbbb77524cb82d693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38a8eaf60f976d7773e7d611e240e0ace91dc487bb06f47950915ae96dc26d289878ec62a62d8ab7dd5fab0cde15d7a9dda3dd97a2dc567185c86572eaa76289
|
7
|
+
data.tar.gz: cd4b309ae655a17efb48818f44004753f957a28e5cdbae462d1f31ab3bb97f4ccaf306408c0276b6df1d547e7ebf37a90ce55bcb04313ac5abbe0a8a0cfeadac
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
!~��WXɿٷWI����Q����Vn�.Qf�-�v?�ڝ�S���T�U�&6<��ŭ�D�g�����j��O�m��}�ԛ!������6� C������
|
2
|
+
���ÖO�n�����؆�m�Hpl���HY�:.ɇ��z��(-�����E�]��pT_�Iڜ"W�Z�������t�ٗf
|
3
|
+
���u�;����a�v[):����C��ujnz���d���D{9�FX�9�d��lgN��j?@�
|
data/lib/xml_col_finder.rb
CHANGED
@@ -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
metadata.gz.sig
CHANGED
Binary file
|