xmlhasher 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -3
- data/Gemfile +1 -3
- data/README.md +17 -18
- data/Rakefile +5 -0
- data/benchmark/benchmark.rb +34 -60
- data/bin/rake +17 -0
- data/lib/xmlhasher/handler.rb +4 -0
- data/lib/xmlhasher/node.rb +1 -1
- data/lib/xmlhasher/version.rb +1 -1
- data/test/xmlhasher/parser_test.rb +6 -0
- data/xmlhasher.gemspec +8 -5
- metadata +64 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0141c719c75bbae939e900964c22fc208f9dd1edcd5043d7dfa3ea1191a41d50
|
4
|
+
data.tar.gz: 4c598efe5871498e9fea2a12d9ecd4acd2a930c7a783a13e5b5715f03e8dc881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81f2afb7c5cb3fa22b51f3567ef84e1c1538a92103f3b1d131ba1d1550f55e7b8e7c7fb18ad506d047cd847d5cff9b13a3bf73b60cbcaeb9d06b0a7eeb182388
|
7
|
+
data.tar.gz: 51242da088ffc005df4db1769582fc1a1ac7adbb7756ff9ecefa0212d54eee3ea45b30804758b230a72f824a9334034adeaa397e7d05978a0a38ac320f56f150
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.5.1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -56,30 +56,29 @@ XmlHasher.parse("<tag1><tag2>content</tag2></tag1>")
|
|
56
56
|
```
|
57
57
|
## Benchmarks
|
58
58
|
|
59
|
-
How fast is it? Try it for yourself
|
59
|
+
How fast is it? Try it for yourself `rake benchmark`
|
60
60
|
|
61
|
-
```
|
61
|
+
```sh
|
62
62
|
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)
|
63
|
+
user system total real
|
64
|
+
activesupport(rexml) 0.196861 0.000692 0.197553 ( 0.197756)
|
65
|
+
activesupport(libxml) 0.028840 0.000176 0.029016 ( 0.029037)
|
66
|
+
activesupport(nokogiri) 0.044063 0.000516 0.044579 ( 0.044618)
|
67
|
+
xmlsimple 0.225291 0.014291 0.239582 ( 0.239756)
|
68
|
+
nori 0.048385 0.000379 0.048764 ( 0.048806)
|
69
|
+
xmlhasher 0.011791 0.000098 0.011889 ( 0.011895)
|
71
70
|
|
72
71
|
Converting large xml from file to Hash:
|
72
|
+
user system total real
|
73
|
+
activesupport(rexml) 25.891326 0.144542 26.035868 ( 26.052577)
|
74
|
+
activesupport(libxml) 3.911317 0.072332 3.983649 ( 3.985904)
|
75
|
+
activesupport(nokogiri) 6.126251 0.061193 6.187444 ( 6.191296)
|
76
|
+
xmlsimple 26.128386 0.120480 26.248866 ( 26.265013)
|
77
|
+
nori 6.347459 0.028522 6.375981 ( 6.380416)
|
78
|
+
xmlhasher 1.738668 0.027549 1.766217 ( 1.767256)
|
73
79
|
|
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
80
|
```
|
82
|
-
Note: benchmarks were generated on a Macbook Pro using Ruby
|
81
|
+
Note: benchmarks were generated on a 2015 Macbook Pro using Ruby 2.5.1
|
83
82
|
|
84
83
|
## Requirements
|
85
84
|
|
data/Rakefile
CHANGED
data/benchmark/benchmark.rb
CHANGED
@@ -4,92 +4,66 @@ require 'benchmark'
|
|
4
4
|
require 'xmlhasher'
|
5
5
|
begin
|
6
6
|
require 'nori'
|
7
|
-
rescue
|
7
|
+
rescue LoadError
|
8
8
|
puts "nori gem in not installed, run 'gem install nori'"
|
9
9
|
end
|
10
10
|
begin
|
11
11
|
require 'active_support/core_ext/hash/conversions'
|
12
|
-
rescue
|
12
|
+
rescue LoadError
|
13
13
|
puts "active_support gem in not installed, run 'gem install activesupport'"
|
14
14
|
end
|
15
15
|
begin
|
16
16
|
require 'xmlsimple'
|
17
|
-
rescue
|
17
|
+
rescue LoadError
|
18
18
|
puts "xmlsimple gem in not installed, run 'gem install xml-simple'"
|
19
19
|
end
|
20
20
|
begin
|
21
21
|
require 'nokogiri'
|
22
|
-
rescue
|
22
|
+
rescue LoadError
|
23
23
|
puts "nokogiri gem in not installed, run 'gem install nokogiri'"
|
24
24
|
end
|
25
25
|
begin
|
26
26
|
require 'libxml'
|
27
|
-
rescue
|
27
|
+
rescue LoadError
|
28
28
|
puts "libxml gem in not installed, run 'gem install libxml-ruby'"
|
29
29
|
end
|
30
30
|
|
31
31
|
|
32
|
-
runs
|
33
|
-
|
34
|
-
puts 'Converting small xml from text to Hash:'
|
35
|
-
Benchmark.bm 10 do |x|
|
36
|
-
ActiveSupport::XmlMini.backend = ActiveSupport::XmlMini_REXML
|
37
|
-
x.report 'activesupport(rexml) ' do
|
38
|
-
runs.times { Hash.from_xml(xml) }
|
39
|
-
end
|
32
|
+
def benchmark(runs, xml)
|
33
|
+
label_width = 25 # needs to be >= any label's size
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
Benchmark.bm(label_width) do |x|
|
36
|
+
ActiveSupport::XmlMini.backend = ActiveSupport::XmlMini_REXML
|
37
|
+
x.report 'activesupport(rexml)' do
|
38
|
+
runs.times { Hash.from_xml(xml) }
|
39
|
+
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
ActiveSupport::XmlMini.backend = 'LibXML'
|
42
|
+
x.report 'activesupport(libxml)' do
|
43
|
+
runs.times { Hash.from_xml(xml) }
|
44
|
+
end
|
50
45
|
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
ActiveSupport::XmlMini.backend = 'Nokogiri'
|
47
|
+
x.report 'activesupport(nokogiri)' do
|
48
|
+
runs.times { Hash.from_xml(xml) }
|
49
|
+
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
x.report 'xmlsimple' do
|
52
|
+
runs.times { XmlSimple.xml_in(xml) }
|
53
|
+
end
|
58
54
|
|
59
|
-
|
60
|
-
|
55
|
+
x.report 'nori' do
|
56
|
+
runs.times { Nori.new(:advanced_typecasting => false).parse(xml) }
|
57
|
+
end
|
58
|
+
|
59
|
+
x.report 'xmlhasher' do
|
60
|
+
runs.times { XmlHasher.parse(xml) }
|
61
|
+
end
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
64
|
-
puts
|
65
|
-
|
66
|
-
path = File.expand_path('../../test/fixtures/institutions.xml', __FILE__)
|
65
|
+
puts 'Converting small xml from text to Hash:'
|
66
|
+
benchmark(100, File.read(File.expand_path('../../test/fixtures/institution.xml', __FILE__)))
|
67
67
|
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
|
68
|
+
benchmark(5, File.read(File.expand_path('../../test/fixtures/institutions.xml', __FILE__)))
|
69
|
+
puts
|
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rake' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rake", "rake")
|
data/lib/xmlhasher/handler.rb
CHANGED
data/lib/xmlhasher/node.rb
CHANGED
@@ -17,7 +17,7 @@ module XmlHasher
|
|
17
17
|
if children.size == 1
|
18
18
|
h[name].merge!(children.first.to_hash)
|
19
19
|
else
|
20
|
-
h[name].merge!(children.group_by { |
|
20
|
+
h[name].merge!(children.group_by { |c| c.name }.inject({}) { |r, (k, v)| v.length == 1 ? r.merge!(v.first.to_hash) : r[k] = v.map { |c| c.to_hash[c.name] }; r })
|
21
21
|
end
|
22
22
|
end
|
23
23
|
h[name] = nil if h[name].empty?
|
data/lib/xmlhasher/version.rb
CHANGED
@@ -241,4 +241,10 @@ class XmlhasherTest < Test::Unit::TestCase
|
|
241
241
|
expected = {:tag => nil}
|
242
242
|
assert_equal expected, XmlHasher::Parser.new.parse(xml)
|
243
243
|
end
|
244
|
+
|
245
|
+
def test_cdata_value
|
246
|
+
xml = %[<title><![CDATA[Midhir uploaded a photo.]]></title>]
|
247
|
+
expected = {:title => "Midhir uploaded a photo."}
|
248
|
+
assert_equal expected, XmlHasher::Parser.new.parse(xml)
|
249
|
+
end
|
244
250
|
end
|
data/xmlhasher.gemspec
CHANGED
@@ -14,16 +14,19 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ['lib']
|
20
19
|
|
21
20
|
spec.required_ruby_version = '>= 1.9.3'
|
22
21
|
spec.required_rubygems_version = '>= 1.3.6'
|
23
22
|
|
24
|
-
spec.add_dependency 'ox', '2.10.0'
|
25
|
-
spec.add_dependency 'escape_utils', '~> 1.2'
|
23
|
+
spec.add_dependency 'ox', '~> 2.10.0'
|
24
|
+
spec.add_dependency 'escape_utils', '~> 1.2'
|
26
25
|
|
27
|
-
spec.add_development_dependency 'rake'
|
28
|
-
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.10'
|
29
|
+
spec.add_development_dependency 'test-unit', '~> 3.2'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.14.1'
|
31
|
+
spec.add_development_dependency 'coveralls', '~> 0.8.21'
|
29
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlhasher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene Drabkin
|
@@ -14,14 +14,14 @@ dependencies:
|
|
14
14
|
name: ox
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.10.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.10.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -31,9 +31,6 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.2'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 1.2.0
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -41,37 +38,90 @@ dependencies:
|
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
40
|
version: '1.2'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.2.0
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rake
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
|
-
- - "
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
|
-
- - "
|
52
|
+
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: '0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: bundler
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
|
-
- - "
|
59
|
+
- - ">="
|
66
60
|
- !ruby/object:Gem::Version
|
67
61
|
version: '0'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
|
-
- - "
|
66
|
+
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.14.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.14.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.21
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.8.21
|
75
125
|
description: Fast XML to Ruby Hash converter
|
76
126
|
email:
|
77
127
|
- gene.drabkin@gmail.com
|
@@ -88,6 +138,7 @@ files:
|
|
88
138
|
- README.md
|
89
139
|
- Rakefile
|
90
140
|
- benchmark/benchmark.rb
|
141
|
+
- bin/rake
|
91
142
|
- lib/xmlhasher.rb
|
92
143
|
- lib/xmlhasher/configurable.rb
|
93
144
|
- lib/xmlhasher/handler.rb
|