xmlhasher 1.0.1 → 1.0.6
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 +5 -5
- data/.rubocop.yml +30 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -13
- data/CHANGELOG.md +78 -0
- data/Gemfile +5 -3
- data/README.md +23 -20
- data/Rakefile +8 -1
- data/benchmark/benchmark.rb +36 -61
- data/bin/rake +17 -0
- data/lib/xmlhasher.rb +6 -1
- data/lib/xmlhasher/configurable.rb +6 -4
- data/lib/xmlhasher/handler.rb +19 -5
- data/lib/xmlhasher/node.rb +30 -13
- data/lib/xmlhasher/parser.rb +2 -1
- data/lib/xmlhasher/util.rb +2 -0
- data/lib/xmlhasher/version.rb +3 -1
- data/scripts/ci +26 -0
- data/xmlhasher.gemspec +17 -12
- metadata +88 -33
- data/test/fixtures/institution.xml +0 -43
- data/test/fixtures/institutions.xml +0 -1
- data/test/test_helper.rb +0 -22
- data/test/xmlhasher/parser_test.rb +0 -244
- data/test/xmlhasher/xmlhasher_test.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bde73682245b3ba9ec69944e0dedb7488786205bf38ccfe6f64ac800fbad0f7b
|
4
|
+
data.tar.gz: cbf2f1830e2a7f649376e30408f78d3ef2f26c0e6cf5b1ec6f76da9ecc0e4764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08450792f4de79c0cbd56e20e023739c5c2c095ba355048501912b1736c0efe3f455aa8ff5b880ad177fff7f92863a3bb9358335ed1012ce4f891d0bf51e3979'
|
7
|
+
data.tar.gz: 5373d3fb4e4f0b9644ed80d6d2957576dbfe0e97645f5a54f94e625721bd8142a5b583d0997677869bfd0ac3a1ee8a90ec7bf357532d538141909df09d5f7206
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 200
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Max: 42
|
9
|
+
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Max: 300
|
12
|
+
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Max: 10
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 60
|
18
|
+
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Max: 20
|
21
|
+
|
22
|
+
Style/MissingRespondToMissing:
|
23
|
+
Exclude:
|
24
|
+
- 'lib/xmlhasher.rb'
|
25
|
+
|
26
|
+
Naming/VariableNumber:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Gemspec/RequiredRubyVersion:
|
30
|
+
Enabled: <%= ENV['CI'] != 'true' %>
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.5.1
|
data/.travis.yml
CHANGED
@@ -1,19 +1,10 @@
|
|
1
1
|
language: ruby
|
2
|
-
bundler_args: "--without development"
|
3
|
-
before_install:
|
4
|
-
- gem install bundler
|
5
2
|
rvm:
|
6
|
-
-
|
7
|
-
-
|
8
|
-
- 1.9.3
|
9
|
-
- 2.0.0
|
10
|
-
- jruby-18mode
|
11
|
-
- jruby-19mode
|
12
|
-
- rbx
|
13
|
-
- rbx-19mode
|
14
|
-
- ree
|
3
|
+
- 2.5.1
|
4
|
+
- 2.6.3
|
15
5
|
env:
|
16
|
-
-
|
6
|
+
- CI=true
|
17
7
|
script:
|
8
|
+
- ./scripts/ci
|
18
9
|
- gem build xmlhasher.gemspec
|
19
10
|
- gem install xmlhasher-*
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All changes to the XmlHasher gem are documented here. Releases follow semantic versioning.
|
4
|
+
|
5
|
+
## [1.0.6] - 2021-03-10
|
6
|
+
|
7
|
+
- Resolve gem build warnings .
|
8
|
+
- Run tests on CI
|
9
|
+
- Little refactoring for Node hash builder.
|
10
|
+
- Use new ruby style guide and `rubocop` gem.
|
11
|
+
|
12
|
+
## [1.0.5] - 2019-06-16
|
13
|
+
|
14
|
+
- Updated ox version.
|
15
|
+
- Fixed warning for global variable `$INPUT_RECORD_SEPARATOR`.
|
16
|
+
- CHANGELOG.md added.
|
17
|
+
- Use new ruby style guide and `rubocop` gem.
|
18
|
+
- Added transform cache for keys.
|
19
|
+
|
20
|
+
## [1.0.4] - 2018-09-20
|
21
|
+
|
22
|
+
- Added `rake benchmark` command.
|
23
|
+
- Enabled CDATA parsing.
|
24
|
+
- Cleanup travis config.
|
25
|
+
- Updated ox version.
|
26
|
+
|
27
|
+
## [1.0.3] - 2018-09-20
|
28
|
+
|
29
|
+
- Updated ruby version requirement.
|
30
|
+
- Fix deprecation warning on SimpleCov::Formatter::MultiFormatter use.
|
31
|
+
- Update dependencies.
|
32
|
+
|
33
|
+
## [1.0.2] - 2016-02-20
|
34
|
+
|
35
|
+
- Cleaned up support environments.
|
36
|
+
- Updated ruby version requirement.
|
37
|
+
|
38
|
+
## [1.0.1] - 2016-02-20
|
39
|
+
|
40
|
+
- Bumped OX and escape_utils gem dependency versions.
|
41
|
+
|
42
|
+
|
43
|
+
## [1.0.0] - 2016-02-20
|
44
|
+
|
45
|
+
- Small changes in README.md.
|
46
|
+
- Removed roby-head from Travis - too unstable.
|
47
|
+
- Fixed ruby 2.2+ issue with single node parsing.
|
48
|
+
|
49
|
+
## [0.0.6] - 2013-09-09
|
50
|
+
|
51
|
+
- Added script for benchmarks.
|
52
|
+
- Added 'string_keys' option to keep keys at Strings vs Symbols.
|
53
|
+
|
54
|
+
## [0.0.5] - 2013-04-24
|
55
|
+
|
56
|
+
- Test release (CI).
|
57
|
+
|
58
|
+
## [0.0.4] - 2013-04-24
|
59
|
+
|
60
|
+
- Fixed mixed children array detection.
|
61
|
+
- Enable Coveralls.
|
62
|
+
- Add more examples and license into README.md
|
63
|
+
|
64
|
+
## [0.0.3] - 2013-04-24
|
65
|
+
|
66
|
+
- Added escape method for attributes and dependency from `escape_utils` gem.
|
67
|
+
- Some fixes for node children parsing.
|
68
|
+
- Added more tests.
|
69
|
+
|
70
|
+
## [0.0.2] - 2013-04-24
|
71
|
+
|
72
|
+
- Some fixes for node children parsing.
|
73
|
+
- Add more tests.
|
74
|
+
- Updated gem description.
|
75
|
+
|
76
|
+
## [0.0.1] - 2013-04-24
|
77
|
+
|
78
|
+
- The first implementation of the XML parser.
|
data/Gemfile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
|
-
gem '
|
7
|
+
gem 'rubocop', require: false if ENV['CI']
|
6
8
|
|
7
9
|
group :test do
|
10
|
+
gem 'coveralls', require: false
|
8
11
|
gem 'minitest'
|
12
|
+
gem 'simplecov', require: false
|
9
13
|
gem 'test-unit'
|
10
|
-
gem 'simplecov', :require => false
|
11
|
-
gem 'coveralls', :require => false
|
12
14
|
end
|
data/README.md
CHANGED
@@ -19,6 +19,10 @@ or add it to your Gemfile like this:
|
|
19
19
|
gem 'xmlhasher'
|
20
20
|
```
|
21
21
|
|
22
|
+
## Release Notes
|
23
|
+
|
24
|
+
See [CHANGELOG.md](CHANGELOG.md)
|
25
|
+
|
22
26
|
## Usage
|
23
27
|
|
24
28
|
```ruby
|
@@ -40,7 +44,7 @@ end
|
|
40
44
|
# alternatively, specify configuration options when instantiating a Parser
|
41
45
|
parser = XmlHasher::Parser.new(
|
42
46
|
:snakecase => true,
|
43
|
-
:ignore_namespaces => true
|
47
|
+
:ignore_namespaces => true,
|
44
48
|
:string_keys => false
|
45
49
|
)
|
46
50
|
|
@@ -56,34 +60,33 @@ XmlHasher.parse("<tag1><tag2>content</tag2></tag1>")
|
|
56
60
|
```
|
57
61
|
## Benchmarks
|
58
62
|
|
59
|
-
How fast is it? Try it for yourself
|
63
|
+
How fast is it? Try it for yourself `rake benchmark`
|
60
64
|
|
61
|
-
```
|
65
|
+
```sh
|
62
66
|
Converting small xml from text to Hash:
|
63
|
-
|
64
|
-
|
65
|
-
activesupport(
|
66
|
-
activesupport(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
xmlhasher 0.010000 0.000000 0.010000 ( 0.017366)
|
67
|
+
user system total real
|
68
|
+
activesupport(rexml) 0.196861 0.000692 0.197553 ( 0.197756)
|
69
|
+
activesupport(libxml) 0.028840 0.000176 0.029016 ( 0.029037)
|
70
|
+
activesupport(nokogiri) 0.044063 0.000516 0.044579 ( 0.044618)
|
71
|
+
xmlsimple 0.225291 0.014291 0.239582 ( 0.239756)
|
72
|
+
nori 0.048385 0.000379 0.048764 ( 0.048806)
|
73
|
+
xmlhasher 0.011791 0.000098 0.011889 ( 0.011895)
|
71
74
|
|
72
75
|
Converting large xml from file to Hash:
|
76
|
+
user system total real
|
77
|
+
activesupport(rexml) 25.891326 0.144542 26.035868 ( 26.052577)
|
78
|
+
activesupport(libxml) 3.911317 0.072332 3.983649 ( 3.985904)
|
79
|
+
activesupport(nokogiri) 6.126251 0.061193 6.187444 ( 6.191296)
|
80
|
+
xmlsimple 26.128386 0.120480 26.248866 ( 26.265013)
|
81
|
+
nori 6.347459 0.028522 6.375981 ( 6.380416)
|
82
|
+
xmlhasher 1.738668 0.027549 1.766217 ( 1.767256)
|
73
83
|
|
74
|
-
user system total real
|
75
|
-
activesupport(rexml) 57.230000 0.240000 57.470000 ( 57.460510)
|
76
|
-
activesupport(libxml) # Segmentation fault
|
77
|
-
activesupport(nokogiri) 12.650000 0.250000 12.900000 ( 12.908073)
|
78
|
-
xmlsimple 49.980000 0.160000 50.140000 ( 50.140775)
|
79
|
-
nori 15.590000 0.110000 15.700000 ( 15.697411)
|
80
|
-
xmlhasher 4.290000 0.030000 4.320000 ( 4.316379)
|
81
84
|
```
|
82
|
-
Note: benchmarks were generated on a Macbook Pro using Ruby
|
85
|
+
Note: benchmarks were generated on a 2015 Macbook Pro using Ruby 2.5.1
|
83
86
|
|
84
87
|
## Requirements
|
85
88
|
|
86
|
-
* Ruby
|
89
|
+
* Ruby 2.0.0 or higher
|
87
90
|
|
88
91
|
## Copyright
|
89
92
|
Copyright (c) 2013 Gene Drabkin.
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
5
|
|
@@ -7,4 +9,9 @@ Rake::TestTask.new(:test) do |t|
|
|
7
9
|
t.verbose = true
|
8
10
|
end
|
9
11
|
|
10
|
-
|
12
|
+
desc 'Run the benchmarks'
|
13
|
+
task :benchmark do
|
14
|
+
system('ruby', File.join(File.dirname(__FILE__), 'benchmark', 'benchmark.rb'))
|
15
|
+
end
|
16
|
+
|
17
|
+
task default: :test
|
data/benchmark/benchmark.rb
CHANGED
@@ -1,95 +1,70 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('../lib', __dir__)
|
2
4
|
|
3
5
|
require 'benchmark'
|
4
6
|
require 'xmlhasher'
|
5
7
|
begin
|
6
8
|
require 'nori'
|
7
|
-
rescue
|
9
|
+
rescue LoadError
|
8
10
|
puts "nori gem in not installed, run 'gem install nori'"
|
9
11
|
end
|
10
12
|
begin
|
11
13
|
require 'active_support/core_ext/hash/conversions'
|
12
|
-
rescue
|
14
|
+
rescue LoadError
|
13
15
|
puts "active_support gem in not installed, run 'gem install activesupport'"
|
14
16
|
end
|
15
17
|
begin
|
16
18
|
require 'xmlsimple'
|
17
|
-
rescue
|
19
|
+
rescue LoadError
|
18
20
|
puts "xmlsimple gem in not installed, run 'gem install xml-simple'"
|
19
21
|
end
|
20
22
|
begin
|
21
23
|
require 'nokogiri'
|
22
|
-
rescue
|
24
|
+
rescue LoadError
|
23
25
|
puts "nokogiri gem in not installed, run 'gem install nokogiri'"
|
24
26
|
end
|
25
27
|
begin
|
26
28
|
require 'libxml'
|
27
|
-
rescue
|
29
|
+
rescue LoadError
|
28
30
|
puts "libxml gem in not installed, run 'gem install libxml-ruby'"
|
29
31
|
end
|
30
32
|
|
33
|
+
def benchmark(runs, xml)
|
34
|
+
label_width = 25 # needs to be >= any label's size
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
x.report 'activesupport(rexml) ' do
|
38
|
-
runs.times { Hash.from_xml(xml) }
|
39
|
-
end
|
36
|
+
Benchmark.bm(label_width) do |x|
|
37
|
+
ActiveSupport::XmlMini.backend = ActiveSupport::XmlMini_REXML
|
38
|
+
x.report 'activesupport(rexml)' do
|
39
|
+
runs.times { Hash.from_xml(xml) }
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
ActiveSupport::XmlMini.backend = 'LibXML'
|
43
|
+
x.report 'activesupport(libxml)' do
|
44
|
+
runs.times { Hash.from_xml(xml) }
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
ActiveSupport::XmlMini.backend = 'Nokogiri'
|
48
|
+
x.report 'activesupport(nokogiri)' do
|
49
|
+
runs.times { Hash.from_xml(xml) }
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
x.report 'xmlsimple' do
|
53
|
+
runs.times { XmlSimple.xml_in(xml) }
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
x.report 'nori' do
|
57
|
+
runs.times { Nori.new(advanced_typecasting: false).parse(xml) }
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
x.report 'xmlhasher' do
|
61
|
+
runs.times { XmlHasher.parse(xml) }
|
62
|
+
end
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
|
-
puts
|
65
|
-
|
66
|
-
path = File.expand_path('../../test/fixtures/institutions.xml', __FILE__)
|
66
|
+
puts 'Converting small xml from text to Hash:'
|
67
|
+
benchmark(100, File.read(File.expand_path('../test/fixtures/institution.xml', __dir__)))
|
67
68
|
puts 'Converting large xml from file to Hash:'
|
68
|
-
|
69
|
-
|
70
|
-
x.report 'activesupport(rexml) ' do
|
71
|
-
runs.times { Hash.from_xml(File.new(path)) }
|
72
|
-
end
|
73
|
-
|
74
|
-
ActiveSupport::XmlMini.backend = 'LibXML'
|
75
|
-
x.report 'activesupport(libxml) ' do
|
76
|
-
#runs.times { Hash.from_xml(File.new(path)) } # Segmentation fault
|
77
|
-
end
|
78
|
-
|
79
|
-
ActiveSupport::XmlMini.backend = 'Nokogiri'
|
80
|
-
x.report 'activesupport(nokogiri)' do
|
81
|
-
runs.times { Hash.from_xml(File.new(path)) }
|
82
|
-
end
|
83
|
-
|
84
|
-
x.report 'xmlsimple ' do
|
85
|
-
runs.times { XmlSimple.xml_in(path) }
|
86
|
-
end
|
87
|
-
|
88
|
-
x.report 'nori ' do
|
89
|
-
runs.times { Nori.new(:advanced_typecasting => false).parse(File.new(path).read) } # Nori doesn't support reading from a stream, load the file in memory
|
90
|
-
end
|
91
|
-
|
92
|
-
x.report 'xmlhasher ' do
|
93
|
-
runs.times { XmlHasher.parse(File.new(path)) }
|
94
|
-
end
|
95
|
-
end
|
69
|
+
benchmark(5, File.read(File.expand_path('../test/fixtures/institutions.xml', __dir__)))
|
70
|
+
puts
|
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'bundler/setup'
|
16
|
+
|
17
|
+
load Gem.bin_path('rake', 'rake')
|
data/lib/xmlhasher.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xmlhasher/configurable'
|
2
4
|
require 'xmlhasher/handler'
|
3
5
|
require 'xmlhasher/parser'
|
@@ -17,9 +19,12 @@ module XmlHasher
|
|
17
19
|
|
18
20
|
def method_missing(method_name, *args, &block)
|
19
21
|
return super unless parser.respond_to?(method_name)
|
22
|
+
|
20
23
|
parser.send(method_name, *args, &block)
|
21
24
|
end
|
22
25
|
|
26
|
+
def respond_to_missing?(method_name, include_private = false)
|
27
|
+
super
|
28
|
+
end
|
23
29
|
end
|
24
|
-
|
25
30
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module XmlHasher
|
2
4
|
module Configurable
|
3
|
-
|
4
5
|
attr_writer :snakecase, :ignore_namespaces, :string_keys
|
5
6
|
|
6
|
-
KEYS = [
|
7
|
+
KEYS = %i[snakecase ignore_namespaces string_keys].freeze
|
7
8
|
|
8
9
|
def configure
|
9
10
|
yield self
|
@@ -13,8 +14,9 @@ module XmlHasher
|
|
13
14
|
private
|
14
15
|
|
15
16
|
def options
|
16
|
-
XmlHasher::Configurable::KEYS.
|
17
|
+
XmlHasher::Configurable::KEYS.each_with_object({}) do |key, hash|
|
18
|
+
hash[key] = instance_variable_get(:"@#{key}")
|
19
|
+
end
|
17
20
|
end
|
18
|
-
|
19
21
|
end
|
20
22
|
end
|