extreml 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/extreml.rb +8 -3
- data/lib/extreml/type_element.rb +34 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c29a7f392a3738bfb30da390a0f5300a7eaf0a18b3a362b646ab714960d49bf
|
4
|
+
data.tar.gz: e9aeb041084b680b59cb59e6d3f027b85c187d50f38c51ed7009ec1fd8a69712
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecb15668d52e77309ea60a1e2151391e1b1e8a87ba67dd758e68e2d9ac04a62d4ac85fd000ebb9689e30cc8766e5fb8fc054b4ddab0ec4b6254d30ac860e9f70
|
7
|
+
data.tar.gz: 102ab70c8118fb6bf1d7e5a5012f02036d7a7c15ad5c2409390c63f5fa66f808677b18f12506289f10c1cdf2eb12f9989bdf0c8bdd949ebf2d26022db3850dca
|
data/lib/extreml.rb
CHANGED
@@ -68,7 +68,11 @@ class Extreml
|
|
68
68
|
|
69
69
|
# Returns the document in an Hash form
|
70
70
|
def to_hash
|
71
|
-
return
|
71
|
+
return self.document.to_hash
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_json
|
75
|
+
return self.document.to_json
|
72
76
|
end
|
73
77
|
|
74
78
|
# Retrurns the document in XML format
|
@@ -112,7 +116,8 @@ class Extreml
|
|
112
116
|
return string
|
113
117
|
else
|
114
118
|
attributes = Array.new
|
115
|
-
a = parts[:attributes].scan /[\t\n\r\f ]*(?:(?<namespace>[
|
119
|
+
a = parts[:attributes].scan /[\t\n\r\f ]*(?:(?<namespace>[^\:\=\n\r\f\t ]*):)?(?<property>[^\:\=\n\r\f\t ]*)[\t ]*=[\t ]*"(?<value>[^"]*)"[\t\n\r\f]*/m
|
120
|
+
|
116
121
|
a.each do |p|
|
117
122
|
attributes << {
|
118
123
|
:namespace => p[0],
|
@@ -134,7 +139,7 @@ class Extreml
|
|
134
139
|
attributes = nil
|
135
140
|
else
|
136
141
|
attributes = Array.new
|
137
|
-
a = tags[:attributes].scan /[\t\n\r\f ]*(?:(?<namespace>[
|
142
|
+
a = tags[:attributes].scan /[\t\n\r\f ]*(?:(?<namespace>[^\:\=\n\r\f\t ]*):)?(?<property>[^\:\=\n\r\f\t ]*)[\t ]*=[\t ]*"(?<value>[^"]*)"[\t\n\r\f]*/m
|
138
143
|
a.each do |p|
|
139
144
|
attributes << {
|
140
145
|
:namespace => p[0],
|
data/lib/extreml/type_element.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'pp'
|
24
|
+
require 'json'
|
24
25
|
|
25
26
|
class Extreml::TypeElement
|
26
27
|
|
@@ -123,7 +124,7 @@ class Extreml::TypeElement
|
|
123
124
|
end
|
124
125
|
alias __to_s to_s
|
125
126
|
|
126
|
-
#
|
127
|
+
# Returns the document in XML format
|
127
128
|
def to_xml level = 0
|
128
129
|
xml = ''
|
129
130
|
xml += "#{' ' * level}<#{@namespace.nil? ? '' : "#{@namespace}:"}#{@name}"
|
@@ -156,6 +157,38 @@ class Extreml::TypeElement
|
|
156
157
|
end
|
157
158
|
alias __to_xml to_xml
|
158
159
|
|
160
|
+
# Returns the document in JSON format
|
161
|
+
def to_json
|
162
|
+
return self.to_hash.to_json
|
163
|
+
end
|
164
|
+
alias __to_json to_json
|
165
|
+
|
166
|
+
# Returns a hash of the document
|
167
|
+
def to_hash
|
168
|
+
hash = Hash.new
|
169
|
+
hash = {
|
170
|
+
namespace: @namespace,
|
171
|
+
attributes: @attributes
|
172
|
+
}
|
173
|
+
if @types.empty?
|
174
|
+
hash[:content] = @content
|
175
|
+
else
|
176
|
+
@types.each do |t|
|
177
|
+
obj = self.send(t)
|
178
|
+
if obj.class == Array
|
179
|
+
hash[t] = Array.new
|
180
|
+
obj.each do |o|
|
181
|
+
hash[t] << o.to_hash
|
182
|
+
end
|
183
|
+
else
|
184
|
+
hash[t] = obj.to_hash
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
return hash
|
189
|
+
end
|
190
|
+
alias __to_hash to_hash
|
191
|
+
|
159
192
|
# This method is for debug purposes only, it prints a tree of the document
|
160
193
|
def tree level: 0, attributes: false
|
161
194
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extreml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Boccacini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
This gem allows to read an XML file and access its elements using methods named after the tags.
|