extreml 0.1.4 → 1.0.0

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: 515dc79d9318fd0f9d9c2f99e17fee96d3c87caee86c3eaf09906ffddae31e05
4
- data.tar.gz: 4061c6ebd046960ddc9083189d935624192beb7d04420421be478fc6e2f7f768
3
+ metadata.gz: 6c29a7f392a3738bfb30da390a0f5300a7eaf0a18b3a362b646ab714960d49bf
4
+ data.tar.gz: e9aeb041084b680b59cb59e6d3f027b85c187d50f38c51ed7009ec1fd8a69712
5
5
  SHA512:
6
- metadata.gz: 9142a017555531ff5b9b6f218ec7796c262ef0b33841dc53a112e61060242fcdbba640fddb40a993101df0b77e1905f2afe45f0d197dc7a50f39f92e214054ae
7
- data.tar.gz: 49fd175e6938aaf4c813487ad2dbabd0e1e304ab7b299499304332848e3b9a3b7edf3566708ec3b47f3b7934f6e0475929d7497e27c05ce192ebe8950d38d6b9
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 @document
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>[^:\n\r\f\t]*):)?(?<property>[^=\n\r\f\t ]*)[\t ]*=[\t ]*"(?<value>[^"]*)"[\t\n\r\f]*/m
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>[^:\n\r\f\t]*):)?(?<property>[^=\n\r\f\t ]*)[\t ]*=[\t ]*"(?<value>[^"]*)"[\t\n\r\f]*/m
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],
@@ -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
- # Retrurns the document in XML format
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.1.4
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-16 00:00:00.000000000 Z
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.