dachsfisch 0.2.0 → 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 +4 -4
- data/Gemfile.lock +6 -6
- data/README.md +3 -1
- data/lib/dachsfisch/json2_xml_converter.rb +3 -3
- data/lib/dachsfisch/version.rb +1 -1
- data/lib/dachsfisch/xml2_json_converter.rb +8 -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: 4b57f57926887bccdb029343e6f10257eed76667dbd6201623dca2e371949cd4
|
4
|
+
data.tar.gz: 8e078cf673d76acf54cd8b3aea7acdac70f53ffdfe1558a58193f981c5cd9416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 623c2ae1bd6671fce977ba88f392d8531cc2e63a008e440b74fb7d5b1fcce01bcfdec4727fb35f800ffc43a443e42f6d143d4d78c51f6e81b453e35981dc2f9c
|
7
|
+
data.tar.gz: 02b75ae568aa73b540af54f8ce3f1d7ba8829df216a3d6375b02a34deb8517f8ab4bc04e473f56e538d46bece3ee6889d3457e8c6f3a92e2fc9a202407b55d55
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dachsfisch (0.
|
4
|
+
dachsfisch (1.0.0)
|
5
5
|
nokogiri (>= 1.14.1, < 2.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
mini_portile2 (~> 2.8.2)
|
23
23
|
racc (~> 1.4)
|
24
24
|
parallel (1.23.0)
|
25
|
-
parser (3.2.2.
|
25
|
+
parser (3.2.2.4)
|
26
26
|
ast (~> 2.4.1)
|
27
27
|
racc
|
28
28
|
pry (0.14.2)
|
@@ -31,7 +31,7 @@ GEM
|
|
31
31
|
racc (1.7.1)
|
32
32
|
rainbow (3.1.1)
|
33
33
|
rake (13.0.6)
|
34
|
-
regexp_parser (2.8.
|
34
|
+
regexp_parser (2.8.2)
|
35
35
|
rexml (3.2.6)
|
36
36
|
rspec (3.12.0)
|
37
37
|
rspec-core (~> 3.12.0)
|
@@ -48,12 +48,12 @@ GEM
|
|
48
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
49
|
rspec-support (~> 3.12.0)
|
50
50
|
rspec-support (3.12.1)
|
51
|
-
rubocop (1.
|
51
|
+
rubocop (1.57.1)
|
52
52
|
base64 (~> 0.1.1)
|
53
53
|
json (~> 2.3)
|
54
54
|
language_server-protocol (>= 3.17.0)
|
55
55
|
parallel (~> 1.10)
|
56
|
-
parser (>= 3.2.2.
|
56
|
+
parser (>= 3.2.2.4)
|
57
57
|
rainbow (>= 2.2.2, < 4.0)
|
58
58
|
regexp_parser (>= 1.8, < 3.0)
|
59
59
|
rexml (>= 3.2.5, < 4.0)
|
@@ -80,7 +80,7 @@ GEM
|
|
80
80
|
simplecov_json_formatter (~> 0.1)
|
81
81
|
simplecov-html (0.12.3)
|
82
82
|
simplecov_json_formatter (0.1.4)
|
83
|
-
unicode-display_width (2.
|
83
|
+
unicode-display_width (2.5.0)
|
84
84
|
|
85
85
|
PLATFORMS
|
86
86
|
ruby
|
data/README.md
CHANGED
@@ -22,6 +22,8 @@ The rules for converting XML documents to JSON using Badgerfish are:
|
|
22
22
|
- CDATA sections become properties named `#1`, `#2`, etc.
|
23
23
|
|
24
24
|
Please see our [examples](spec/support/examples.rb) for more details. Those rules are derived from [this list](http://dropbox.ashlock.us/open311/json-xml/).
|
25
|
+
Own additions:
|
26
|
+
- The order of nodes gets saved in `@@order` (JSON is unordered per definition)
|
25
27
|
|
26
28
|
## Installation
|
27
29
|
|
@@ -53,7 +55,7 @@ json = Dachsfisch::XML2JSONConverter.perform(xml: xml)
|
|
53
55
|
### JSON-to-XML
|
54
56
|
|
55
57
|
```ruby
|
56
|
-
json = '{ "alice": { "$"
|
58
|
+
json = '{ "alice": { "$1": "bob", "@@order": ["$1"] }, "@@order": ["alice"] }'
|
57
59
|
xml = Dachsfisch::JSON2XMLConverter.perform(json: json)
|
58
60
|
```
|
59
61
|
|
@@ -23,8 +23,8 @@ module Dachsfisch
|
|
23
23
|
def add_element(xml, element)
|
24
24
|
return unless element.is_a? Hash
|
25
25
|
|
26
|
-
element
|
27
|
-
add_node(xml, key,
|
26
|
+
element['@@order']&.each do |key|
|
27
|
+
add_node(xml, key, element[key]) unless key.start_with?('@')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -44,7 +44,7 @@ module Dachsfisch
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def handle_attribute_and_namespaces(node, element)
|
47
|
-
element.keys.filter {|element_key| element_key.start_with?(
|
47
|
+
element.keys.filter {|element_key| element_key.start_with?(/@[^@]/) }.each do |attribute_key|
|
48
48
|
if attribute_key.start_with? '@xmlns'
|
49
49
|
element[attribute_key].each do |namespace_key, namespace|
|
50
50
|
# add namespace of current scope to node. The root-ns($) gets 'xmlns' as key, named namespaces 'xmlns:name' respectively.
|
data/lib/dachsfisch/version.rb
CHANGED
@@ -14,20 +14,27 @@ module Dachsfisch
|
|
14
14
|
@fragment.elements.deconstruct.each do |root|
|
15
15
|
result[node_name(root)] = extract_node(root)
|
16
16
|
end
|
17
|
+
add_order_to_hash result
|
17
18
|
result.to_json
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
22
|
|
23
|
+
def add_order_to_hash(hash)
|
24
|
+
return if hash.keys.reject {|key| key.start_with?('@') }.empty?
|
25
|
+
|
26
|
+
hash['@@order'] = hash.keys.reject {|key| key.start_with?('@') }
|
27
|
+
end
|
28
|
+
|
22
29
|
def extract_node(node)
|
23
30
|
hash = {}
|
24
31
|
active_namespaces = add_namespaces_to_active_namespaces(node)
|
25
32
|
hash['@xmlns'] = active_namespaces unless active_namespaces.empty?
|
26
|
-
|
27
33
|
handle_attributes(hash, node)
|
28
34
|
node.children.each do |child|
|
29
35
|
handle_content(hash, child)
|
30
36
|
end
|
37
|
+
add_order_to_hash hash
|
31
38
|
hash
|
32
39
|
end
|
33
40
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dachsfisch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|