dachsfisch 0.2.0 → 1.0.2
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/.rubocop.yml +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +40 -47
- data/README.md +3 -1
- data/lib/dachsfisch/json2_xml_converter.rb +4 -4
- data/lib/dachsfisch/version.rb +1 -1
- data/lib/dachsfisch/xml2_json_converter.rb +8 -1
- metadata +4 -5
- data/dachsfisch.gemspec +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0a7f8e368bcd976111c9cb41cb7a2da07b47623fd9ee41d58bdd94aea5fbe75
|
4
|
+
data.tar.gz: 6202fd4795c0e56e438848b76ff7fb18f99f2c011b48b8ffde6ab6772865c2f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4708dc82596fd1a4d765dd71b58aff4ede991dcae0b26f23c14146425a3fc8576e4dde2713c4f450bd992e7686f2edd994c123e3b316cd34137c4bb93bbb260b
|
7
|
+
data.tar.gz: bc461fcea15fff0d9a7eaf35dd97868471ed129a2fd6843f24abffb6b96970b74a6a9de0d617ed336f6de7e6006c2336d436a5567fe017dd27bf9567e25d8b5a
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,86 +1,78 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dachsfisch (0.2
|
4
|
+
dachsfisch (1.0.2)
|
5
5
|
nokogiri (>= 1.14.1, < 2.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
|
-
base64 (0.1.1)
|
12
11
|
coderay (1.1.3)
|
13
|
-
diff-lcs (1.5.
|
14
|
-
docile (1.4.
|
12
|
+
diff-lcs (1.5.1)
|
13
|
+
docile (1.4.1)
|
15
14
|
equivalent-xml (0.6.0)
|
16
15
|
nokogiri (>= 1.4.3)
|
17
|
-
json (2.
|
16
|
+
json (2.8.1)
|
18
17
|
language_server-protocol (3.17.0.3)
|
19
|
-
method_source (1.
|
20
|
-
mini_portile2 (2.8.
|
21
|
-
nokogiri (1.
|
18
|
+
method_source (1.1.0)
|
19
|
+
mini_portile2 (2.8.7)
|
20
|
+
nokogiri (1.16.7)
|
22
21
|
mini_portile2 (~> 2.8.2)
|
23
22
|
racc (~> 1.4)
|
24
|
-
parallel (1.
|
25
|
-
parser (3.
|
23
|
+
parallel (1.26.3)
|
24
|
+
parser (3.3.6.0)
|
26
25
|
ast (~> 2.4.1)
|
27
26
|
racc
|
28
27
|
pry (0.14.2)
|
29
28
|
coderay (~> 1.1)
|
30
29
|
method_source (~> 1.0)
|
31
|
-
racc (1.
|
30
|
+
racc (1.8.1)
|
32
31
|
rainbow (3.1.1)
|
33
|
-
rake (13.
|
34
|
-
regexp_parser (2.
|
35
|
-
|
36
|
-
|
37
|
-
rspec-
|
38
|
-
rspec-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
rspec-expectations (3.12.3)
|
32
|
+
rake (13.2.1)
|
33
|
+
regexp_parser (2.9.2)
|
34
|
+
rspec (3.13.0)
|
35
|
+
rspec-core (~> 3.13.0)
|
36
|
+
rspec-expectations (~> 3.13.0)
|
37
|
+
rspec-mocks (~> 3.13.0)
|
38
|
+
rspec-core (3.13.2)
|
39
|
+
rspec-support (~> 3.13.0)
|
40
|
+
rspec-expectations (3.13.3)
|
43
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
42
|
+
rspec-support (~> 3.13.0)
|
45
43
|
rspec-github (2.4.0)
|
46
44
|
rspec-core (~> 3.0)
|
47
|
-
rspec-mocks (3.
|
45
|
+
rspec-mocks (3.13.2)
|
48
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-support (3.
|
51
|
-
rubocop (1.
|
52
|
-
base64 (~> 0.1.1)
|
47
|
+
rspec-support (~> 3.13.0)
|
48
|
+
rspec-support (3.13.1)
|
49
|
+
rubocop (1.68.0)
|
53
50
|
json (~> 2.3)
|
54
51
|
language_server-protocol (>= 3.17.0)
|
55
52
|
parallel (~> 1.10)
|
56
|
-
parser (>= 3.
|
53
|
+
parser (>= 3.3.0.2)
|
57
54
|
rainbow (>= 2.2.2, < 4.0)
|
58
|
-
regexp_parser (>=
|
59
|
-
|
60
|
-
rubocop-ast (>= 1.28.1, < 2.0)
|
55
|
+
regexp_parser (>= 2.4, < 3.0)
|
56
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
61
57
|
ruby-progressbar (~> 1.7)
|
62
58
|
unicode-display_width (>= 2.4.0, < 3.0)
|
63
|
-
rubocop-ast (1.
|
64
|
-
parser (>= 3.
|
65
|
-
rubocop-
|
66
|
-
rubocop (~> 1.
|
67
|
-
rubocop-
|
68
|
-
rubocop (
|
69
|
-
|
70
|
-
|
71
|
-
rubocop
|
72
|
-
rubocop-rspec (2.24.1)
|
73
|
-
rubocop (~> 1.33)
|
74
|
-
rubocop-capybara (~> 2.17)
|
75
|
-
rubocop-factory_bot (~> 2.22)
|
59
|
+
rubocop-ast (1.34.1)
|
60
|
+
parser (>= 3.3.1.0)
|
61
|
+
rubocop-factory_bot (2.26.1)
|
62
|
+
rubocop (~> 1.61)
|
63
|
+
rubocop-performance (1.22.1)
|
64
|
+
rubocop (>= 1.48.1, < 2.0)
|
65
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
66
|
+
rubocop-rspec (3.2.0)
|
67
|
+
rubocop (~> 1.61)
|
76
68
|
ruby-progressbar (1.13.0)
|
77
69
|
simplecov (0.22.0)
|
78
70
|
docile (~> 1.1)
|
79
71
|
simplecov-html (~> 0.11)
|
80
72
|
simplecov_json_formatter (~> 0.1)
|
81
|
-
simplecov-html (0.
|
73
|
+
simplecov-html (0.13.1)
|
82
74
|
simplecov_json_formatter (0.1.4)
|
83
|
-
unicode-display_width (2.
|
75
|
+
unicode-display_width (2.6.0)
|
84
76
|
|
85
77
|
PLATFORMS
|
86
78
|
ruby
|
@@ -93,9 +85,10 @@ DEPENDENCIES
|
|
93
85
|
rspec
|
94
86
|
rspec-github
|
95
87
|
rubocop
|
88
|
+
rubocop-factory_bot
|
96
89
|
rubocop-performance
|
97
90
|
rubocop-rspec
|
98
91
|
simplecov
|
99
92
|
|
100
93
|
BUNDLED WITH
|
101
|
-
2.
|
94
|
+
2.5.23
|
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
|
|
@@ -32,7 +32,7 @@ module Dachsfisch
|
|
32
32
|
case element
|
33
33
|
when Hash
|
34
34
|
# underscore is used to disambiguate tag names from ruby methods
|
35
|
-
node = xml.send("#{key}_") { add_element(xml, element) }
|
35
|
+
node = xml.send(:"#{key}_") { add_element(xml, element) }
|
36
36
|
handle_attribute_and_namespaces(node, element)
|
37
37
|
when Array
|
38
38
|
element.each do |sub_element|
|
@@ -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.2
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -52,7 +52,6 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- SECURITY.md
|
55
|
-
- dachsfisch.gemspec
|
56
55
|
- lib/dachsfisch.rb
|
57
56
|
- lib/dachsfisch/converter_base.rb
|
58
57
|
- lib/dachsfisch/errors.rb
|
@@ -72,14 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
73
72
|
- - ">="
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
74
|
+
version: '3.3'
|
76
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
76
|
requirements:
|
78
77
|
- - ">="
|
79
78
|
- !ruby/object:Gem::Version
|
80
79
|
version: '0'
|
81
80
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.5.23
|
83
82
|
signing_key:
|
84
83
|
specification_version: 4
|
85
84
|
summary: Badgerfish implementation
|
data/dachsfisch.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/dachsfisch/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'dachsfisch'
|
7
|
-
spec.version = Dachsfisch::VERSION
|
8
|
-
spec.authors = ['Karol']
|
9
|
-
spec.email = ['git@koehn.pro']
|
10
|
-
|
11
|
-
spec.summary = 'Badgerfish implementation'
|
12
|
-
spec.description = 'Implements a bidirectional converter for XML and JSON based on the badgerfish-specification'
|
13
|
-
spec.homepage = 'https://github.com/openHPI/dachsfisch'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '>= 3.2'
|
16
|
-
|
17
|
-
# Specify which files should be added to the gem when it is released.
|
18
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
-
spec.files = Dir.chdir(__dir__) do
|
20
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
21
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
spec.bindir = 'exe'
|
26
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) {|f| File.basename(f) }
|
27
|
-
spec.require_paths = ['lib']
|
28
|
-
|
29
|
-
spec.add_dependency 'nokogiri', '>= 1.14.1', '< 2.0.0'
|
30
|
-
|
31
|
-
spec.metadata['rubygems_mfa_required'] = 'true'
|
32
|
-
end
|