xmlhasher 1.0.1 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d51d5ef116a4b3354623bbc37795837110b22d3a
4
- data.tar.gz: 16c52567fc5e14ec6dbcff34fbb9a7e3b7ce2517
2
+ SHA256:
3
+ metadata.gz: bde73682245b3ba9ec69944e0dedb7488786205bf38ccfe6f64ac800fbad0f7b
4
+ data.tar.gz: cbf2f1830e2a7f649376e30408f78d3ef2f26c0e6cf5b1ec6f76da9ecc0e4764
5
5
  SHA512:
6
- metadata.gz: 8342953c54eacbdf8cb395e8eb0b3b4c1843b4a4ddc720f238a4cb45f7db2a29802511d7396ebaa147c367b4b14c4fb501118759b270b3be689c9927f7ab000e
7
- data.tar.gz: c62782286859b2462d6c061a410f295ca09710d7c642220b2906465ff9691a4ca395e331395cc67502cdb159f9e35ee8e871249e104212ca2963ccb24ef4e63d
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
- ruby-2.3.0
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
- - 1.8.7
7
- - 1.9.2
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
- - JRUBY_OPTS="-Xcext.enabled=true"
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 'rake'
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 - [benchmark.rb](https://github.com/cloocher/xmlhasher/blob/master/benchmark/benchmark.rb)
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
- user system total real
65
- activesupport(rexml) 0.380000 0.000000 0.380000 ( 0.385326)
66
- activesupport(libxml) 0.060000 0.000000 0.060000 ( 0.062008)
67
- activesupport(nokogiri) 0.090000 0.000000 0.090000 ( 0.089466)
68
- xmlsimple 0.480000 0.010000 0.490000 ( 0.490938)
69
- nori 0.120000 0.000000 0.120000 ( 0.123612)
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 1.9.3p392
85
+ Note: benchmarks were generated on a 2015 Macbook Pro using Ruby 2.5.1
83
86
 
84
87
  ## Requirements
85
88
 
86
- * Ruby 1.8.7 or higher
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
- task :default => :test
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
@@ -1,95 +1,70 @@
1
- $:.push File.expand_path('../../lib', __FILE__)
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
- runs = 100
33
- xml = File.read(File.expand_path('../../test/fixtures/institution.xml', __FILE__))
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
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
- ActiveSupport::XmlMini.backend = 'LibXML'
42
- x.report 'activesupport(libxml) ' do
43
- runs.times { Hash.from_xml(xml) }
44
- end
42
+ ActiveSupport::XmlMini.backend = 'LibXML'
43
+ x.report 'activesupport(libxml)' do
44
+ runs.times { Hash.from_xml(xml) }
45
+ end
45
46
 
46
- ActiveSupport::XmlMini.backend = 'Nokogiri'
47
- x.report 'activesupport(nokogiri)' do
48
- runs.times { Hash.from_xml(xml) }
49
- end
47
+ ActiveSupport::XmlMini.backend = 'Nokogiri'
48
+ x.report 'activesupport(nokogiri)' do
49
+ runs.times { Hash.from_xml(xml) }
50
+ end
50
51
 
51
- x.report 'xmlsimple ' do
52
- runs.times { XmlSimple.xml_in(xml) }
53
- end
52
+ x.report 'xmlsimple' do
53
+ runs.times { XmlSimple.xml_in(xml) }
54
+ end
54
55
 
55
- x.report 'nori ' do
56
- runs.times { Nori.new(:advanced_typecasting => false).parse(xml) }
57
- end
56
+ x.report 'nori' do
57
+ runs.times { Nori.new(advanced_typecasting: false).parse(xml) }
58
+ end
58
59
 
59
- x.report 'xmlhasher ' do
60
- runs.times { XmlHasher.parse(xml) }
60
+ x.report 'xmlhasher' do
61
+ runs.times { XmlHasher.parse(xml) }
62
+ end
61
63
  end
62
64
  end
63
65
 
64
- puts
65
- runs = 5
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
- Benchmark.bm 5 do |x|
69
- ActiveSupport::XmlMini.backend = ActiveSupport::XmlMini_REXML
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 = [:snakecase, :ignore_namespaces, :string_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.inject({}) { |hash, key| hash[key] = instance_variable_get(:"@#{key}"); hash }
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