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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b770b4fa107d42b19b2cccbf725b0677d63176f2bae0754e8d3b566b642ab99
4
- data.tar.gz: a83446b885e9596e174f79e45337d08f97925f7bcb7ad76d8bbfa74c27a5228c
3
+ metadata.gz: e0a7f8e368bcd976111c9cb41cb7a2da07b47623fd9ee41d58bdd94aea5fbe75
4
+ data.tar.gz: 6202fd4795c0e56e438848b76ff7fb18f99f2c011b48b8ffde6ab6772865c2f7
5
5
  SHA512:
6
- metadata.gz: f15b9899108feb5971a743ac490bd1107849990a7a1381c581ef46e12adabdd484f559a8a099dd13e7e5414a9251c86466a01683376a5f63d920d5c9f4c9ab54
7
- data.tar.gz: 2e45884b0a96d04f39b72003e80bed357ea44d8846f470b7a46ef7da4642e29abfb8c28e17e626afd66f5010f6aeb3dede170f702cca5943ee6ae44627f01eaa
6
+ metadata.gz: 4708dc82596fd1a4d765dd71b58aff4ede991dcae0b26f23c14146425a3fc8576e4dde2713c4f450bd992e7686f2edd994c123e3b316cd34137c4bb93bbb260b
7
+ data.tar.gz: bc461fcea15fff0d9a7eaf35dd97868471ed129a2fd6843f24abffb6b96970b74a6a9de0d617ed336f6de7e6006c2336d436a5567fe017dd27bf9567e25d8b5a
data/.rubocop.yml CHANGED
@@ -10,7 +10,7 @@ inherit_from:
10
10
  - .rubocop/style.yml
11
11
 
12
12
  AllCops:
13
- TargetRubyVersion: 3.2
13
+ TargetRubyVersion: 3.3
14
14
  UseCache: True
15
15
  NewCops: enable
16
16
  Exclude:
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ gem 'rake'
11
11
  gem 'rspec'
12
12
  gem 'rspec-github'
13
13
  gem 'rubocop'
14
+ gem 'rubocop-factory_bot'
14
15
  gem 'rubocop-performance'
15
16
  gem 'rubocop-rspec'
16
17
  gem 'simplecov'
data/Gemfile.lock CHANGED
@@ -1,86 +1,78 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dachsfisch (0.2.0)
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.0)
14
- docile (1.4.0)
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.6.3)
16
+ json (2.8.1)
18
17
  language_server-protocol (3.17.0.3)
19
- method_source (1.0.0)
20
- mini_portile2 (2.8.4)
21
- nokogiri (1.15.4)
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.23.0)
25
- parser (3.2.2.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.7.1)
30
+ racc (1.8.1)
32
31
  rainbow (3.1.1)
33
- rake (13.0.6)
34
- regexp_parser (2.8.1)
35
- rexml (3.2.6)
36
- rspec (3.12.0)
37
- rspec-core (~> 3.12.0)
38
- rspec-expectations (~> 3.12.0)
39
- rspec-mocks (~> 3.12.0)
40
- rspec-core (3.12.2)
41
- rspec-support (~> 3.12.0)
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.12.0)
42
+ rspec-support (~> 3.13.0)
45
43
  rspec-github (2.4.0)
46
44
  rspec-core (~> 3.0)
47
- rspec-mocks (3.12.6)
45
+ rspec-mocks (3.13.2)
48
46
  diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.12.0)
50
- rspec-support (3.12.1)
51
- rubocop (1.56.4)
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.2.2.3)
53
+ parser (>= 3.3.0.2)
57
54
  rainbow (>= 2.2.2, < 4.0)
58
- regexp_parser (>= 1.8, < 3.0)
59
- rexml (>= 3.2.5, < 4.0)
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.29.0)
64
- parser (>= 3.2.1.0)
65
- rubocop-capybara (2.19.0)
66
- rubocop (~> 1.41)
67
- rubocop-factory_bot (2.24.0)
68
- rubocop (~> 1.33)
69
- rubocop-performance (1.19.1)
70
- rubocop (>= 1.7.0, < 2.0)
71
- rubocop-ast (>= 0.4.0)
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.12.3)
73
+ simplecov-html (0.13.1)
82
74
  simplecov_json_formatter (0.1.4)
83
- unicode-display_width (2.4.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.4.19
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": { "$" : "bob" } }'
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.each do |key, value|
27
- add_node(xml, key, value) unless key.start_with?('@')
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?('@') }.each do |attribute_key|
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dachsfisch
4
- VERSION = '0.2.0'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -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.0
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: 2023-10-03 00:00:00.000000000 Z
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.2'
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.4.6
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