rexleparser 0.9.7 → 0.9.8
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 +0 -0
- data/lib/rexleparser.rb +52 -52
- data.tar.gz.sig +0 -0
- metadata +3 -3
- 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: 6b2983f6245146772e1fb82307a06168ed3d3c07b3a96d85c4089aec35712a9d
|
4
|
+
data.tar.gz: e1b14339a868bc524e424e648e64ff957aa4b8aa25123d8359cb0e5c8c08939d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21e7bd2777aaff51cfe10f83d4b39b268d6fe3f188bea5ef08cedd5e899ae7d5798d19c176219e02fb64526348bacd939b3871984cff428e5d96d74095c20c99
|
7
|
+
data.tar.gz: 0b243a97ec7983176aff54db53482abf0449fd1c8c2294ea8b7995957e76fda61cee56f1155aa57d59bf3f969276f927932e9dff2d549d1d62a9ecec7c3e9e7d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/rexleparser.rb
CHANGED
@@ -7,49 +7,49 @@
|
|
7
7
|
class Attributes < Hash
|
8
8
|
|
9
9
|
class Value < String
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(value)
|
12
12
|
#jr2020-04-30 super(value.gsub("'", '''))
|
13
13
|
super(value)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def <(val2)
|
17
17
|
self.to_f < val2.to_f
|
18
|
-
end
|
19
|
-
|
18
|
+
end
|
19
|
+
|
20
20
|
def >(val2)
|
21
21
|
self.to_f > val2.to_f
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def inspect()
|
25
25
|
super().gsub('<','<',).gsub('>','>').gsub('&pos;',"'")
|
26
26
|
end
|
27
|
-
|
28
|
-
def to_s()
|
27
|
+
|
28
|
+
def to_s(unescape: true)
|
29
29
|
#jr2020-07-18 self.gsub('<','<',).gsub('>','>').gsub('&pos;',"'")
|
30
|
-
self.gsub('&','&').gsub('&pos;',"'")
|
30
|
+
self.gsub('&','&').gsub('&pos;',"'") if unescape
|
31
31
|
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
35
|
def initialize(h={})
|
36
36
|
super().merge! h
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def []=(k,v)
|
40
40
|
super(k, k != :class ? Value.new(v) : v)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def merge(h)
|
44
44
|
|
45
|
-
h2 = h.inject({}) do |r, kv|
|
45
|
+
h2 = h.inject({}) do |r, kv|
|
46
46
|
k, raw_v = kv
|
47
47
|
v = raw_v.is_a?(String) ? Value.new(raw_v) : raw_v
|
48
|
-
r.merge(k => v)
|
48
|
+
r.merge(k => v)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
super(h2)
|
52
|
-
|
52
|
+
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -65,7 +65,7 @@ class RexleParser
|
|
65
65
|
super()
|
66
66
|
s = raw_s.clone.strip
|
67
67
|
return if s.empty?
|
68
|
-
|
68
|
+
|
69
69
|
raw_xml, raw_instrctns = if s.lines.first =~ /<?xml/ then
|
70
70
|
s.split(/(?=\?>\s*<\w)/,2).reverse
|
71
71
|
else
|
@@ -77,10 +77,10 @@ class RexleParser
|
|
77
77
|
@to_a = reverse(parse_node(raw_xml.strip.reverse))
|
78
78
|
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
private
|
82
82
|
|
83
|
-
|
83
|
+
|
84
84
|
def scan_next(r, tagname)
|
85
85
|
|
86
86
|
j = tagname
|
@@ -89,7 +89,7 @@ class RexleParser
|
|
89
89
|
|
90
90
|
# end tag match
|
91
91
|
tag = r[/^>[^<]+</]
|
92
|
-
|
92
|
+
|
93
93
|
if tag[1][/[ \w"']/] and tag[-2] != '/' then
|
94
94
|
|
95
95
|
# is it the end tag to match the start tag?
|
@@ -97,18 +97,18 @@ class RexleParser
|
|
97
97
|
end_tag = tag[/^>[^>]*#{j}<$/]
|
98
98
|
|
99
99
|
if end_tag then
|
100
|
-
|
100
|
+
|
101
101
|
j = nil
|
102
102
|
return [:end_tag, end_tag]
|
103
103
|
|
104
104
|
elsif tag[/^>[^>]*\w+<$/] then
|
105
105
|
# broken tag found
|
106
106
|
broken_tag = tag
|
107
|
-
return [:child, [nil, [], broken_tag]] if broken_tag
|
107
|
+
return [:child, [nil, [], broken_tag]] if broken_tag
|
108
108
|
else
|
109
|
-
|
109
|
+
|
110
110
|
text, newtag = tag.sub('>',';tg&').split(/>/,2)
|
111
|
-
|
111
|
+
|
112
112
|
if newtag then
|
113
113
|
tag = newtag
|
114
114
|
r.prepend '>' + tag
|
@@ -117,16 +117,16 @@ class RexleParser
|
|
117
117
|
return [:child, text]
|
118
118
|
end
|
119
119
|
elsif r[0,3] == '>--' then # comment tag found
|
120
|
-
|
120
|
+
|
121
121
|
r.slice!(0,3)
|
122
122
|
i = r =~ /(\-\-!<)/
|
123
123
|
s = r.slice!(0,i)
|
124
124
|
r.slice!(0,4)
|
125
125
|
|
126
126
|
tagname, content = ['-!',s]
|
127
|
-
|
127
|
+
|
128
128
|
return [:child, [">#{tagname}<", [content], ">#{tagname}/<"]]
|
129
|
-
|
129
|
+
|
130
130
|
elsif r[0,3] == '>]]' then # CDATA tag found
|
131
131
|
|
132
132
|
r.slice!(0,3)
|
@@ -136,22 +136,22 @@ class RexleParser
|
|
136
136
|
|
137
137
|
tagname, content = ['[!',s]
|
138
138
|
|
139
|
-
return [:child, [">#{tagname}<", [content], ">#{tagname}/<"]]
|
140
|
-
|
139
|
+
return [:child, [">#{tagname}<", [content], ">#{tagname}/<"]]
|
140
|
+
|
141
141
|
elsif tag[/>\/|\/<$/] or tag[/^>.*[\w!]+\/<$/] then
|
142
|
-
|
143
|
-
return [:newnode]
|
144
|
-
|
142
|
+
|
143
|
+
return [:newnode]
|
144
|
+
|
145
145
|
else
|
146
|
-
|
147
|
-
r.sub!('>',';tg&')
|
146
|
+
|
147
|
+
r.sub!('>',';tg&')
|
148
148
|
i = r =~ />(?:[\-\/"'\w]|\]\])/ # collect until a tag is found or a CDATA element
|
149
149
|
text = r.slice!(0,i)
|
150
150
|
|
151
151
|
return [:child, text] if text
|
152
152
|
|
153
153
|
end # end of tag match
|
154
|
-
|
154
|
+
|
155
155
|
else
|
156
156
|
|
157
157
|
# it's a text value
|
@@ -161,12 +161,12 @@ class RexleParser
|
|
161
161
|
return [:child, text] if text
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
def parse_node(r, j=nil)
|
166
|
-
|
166
|
+
|
167
167
|
return unless r.length > 0
|
168
168
|
tag = r.slice!(/^>[^<]+</) if (r =~ /^>[^<]+</) == 0
|
169
|
-
tagname = tag[/([\w!:]+)\/?<$/,1]
|
169
|
+
tagname = tag[/([\w!:]+)\/?<$/,1]
|
170
170
|
|
171
171
|
# self closing tag?
|
172
172
|
if tag[/^>\/.*#{tagname}<$/m] then
|
@@ -180,16 +180,16 @@ class RexleParser
|
|
180
180
|
start_tag.reverse + '; context: ' + r[0..120].reverse.inspect
|
181
181
|
end
|
182
182
|
|
183
|
-
until end_tag do
|
184
|
-
|
185
|
-
key, res = scan_next r, tagname
|
186
|
-
|
187
|
-
case key
|
183
|
+
until end_tag do
|
184
|
+
|
185
|
+
key, res = scan_next r, tagname
|
186
|
+
|
187
|
+
case key
|
188
188
|
when :end_tag
|
189
189
|
end_tag = res
|
190
190
|
r2 = [start_tag, children, end_tag]
|
191
191
|
end_tag = nil
|
192
|
-
|
192
|
+
|
193
193
|
return r2
|
194
194
|
when :child
|
195
195
|
children << res
|
@@ -204,13 +204,13 @@ class RexleParser
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def get_attributes(raw_attributes)
|
207
|
-
|
207
|
+
|
208
208
|
r1 = /([\w\-:\(\)]+\='[^']*)'/
|
209
209
|
r2 = /([\w\-:\(\)]+\="[^"]*)"/
|
210
|
-
|
210
|
+
|
211
211
|
r = raw_attributes.scan(/#{r1}|#{r2}/).map(&:compact)\
|
212
212
|
.flatten.inject(Attributes.new) do |r, x|
|
213
|
-
attr_name, raw_val = x.split(/=/,2)
|
213
|
+
attr_name, raw_val = x.split(/=/,2)
|
214
214
|
val = attr_name != 'class' ? raw_val[1..-1] : raw_val[1..-1].split
|
215
215
|
r.merge(attr_name.to_sym => val)
|
216
216
|
end
|
@@ -219,17 +219,17 @@ class RexleParser
|
|
219
219
|
end
|
220
220
|
|
221
221
|
def reverse(raw_obj)
|
222
|
-
|
222
|
+
|
223
223
|
return unless raw_obj
|
224
224
|
obj = raw_obj.clone
|
225
225
|
return obj.reverse! if obj.is_a? String
|
226
226
|
|
227
227
|
tag = obj.pop.reverse
|
228
|
-
|
228
|
+
|
229
229
|
children = obj[-1]
|
230
230
|
|
231
231
|
r = children.reverse.map {|x| reverse(x)}
|
232
|
-
|
232
|
+
|
233
233
|
return [tag[/[!\-\w:\[]+/], get_attributes(tag), *r]
|
234
|
-
end
|
234
|
+
end
|
235
235
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexleparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,10 +35,10 @@ cert_chain:
|
|
35
35
|
cF/nszU+U7PJ1WnQ+W7QTqoViru4N0S9bwi3YV5F5NPPeVnnrtmC2yruRfgTCI4b
|
36
36
|
3nEas0DJDZbQSkPP1mVcybEA
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-01-01 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description:
|
41
|
-
email:
|
41
|
+
email: digital.robertson@gmail.com
|
42
42
|
executables: []
|
43
43
|
extensions: []
|
44
44
|
extra_rdoc_files: []
|
metadata.gz.sig
CHANGED
Binary file
|