xmlhasher 1.0.4 → 1.0.5

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
2
  SHA256:
3
- metadata.gz: 0141c719c75bbae939e900964c22fc208f9dd1edcd5043d7dfa3ea1191a41d50
4
- data.tar.gz: 4c598efe5871498e9fea2a12d9ecd4acd2a930c7a783a13e5b5715f03e8dc881
3
+ metadata.gz: cf67f59279e556373a5f608b70b21e435eb64173316bf82ec7461bc444a193c4
4
+ data.tar.gz: 446fd644b407a93c467dd8c24df75afe9308f04d15000b313ceec1898893ea2b
5
5
  SHA512:
6
- metadata.gz: 81f2afb7c5cb3fa22b51f3567ef84e1c1538a92103f3b1d131ba1d1550f55e7b8e7c7fb18ad506d047cd847d5cff9b13a3bf73b60cbcaeb9d06b0a7eeb182388
7
- data.tar.gz: 51242da088ffc005df4db1769582fc1a1ac7adbb7756ff9ecefa0212d54eee3ea45b30804758b230a72f824a9334034adeaa397e7d05978a0a38ac320f56f150
6
+ metadata.gz: d4c32e4578bb6bae7c5e63b485e5dd84a304374fa35aa22f134a15b05faa663f29adaf5cb615afa63ec43f1a9d8a8a84bdaf9e8359610d9a86ae4ea625da43fc
7
+ data.tar.gz: 22523c1d1089d9cf6add10df187b43175551138cb767be51c78ae1befe6dcba17a4bd6ce0a3b9f4b79ecadce1568309dab811d19c6bd5674e0ee43346acbf1d6
@@ -0,0 +1,27 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 200
9
+
10
+ Metrics/AbcSize:
11
+ Max: 42
12
+
13
+ Metrics/ClassLength:
14
+ Max: 300
15
+
16
+ Metrics/CyclomaticComplexity:
17
+ Max: 10
18
+
19
+ Metrics/MethodLength:
20
+ Max: 60
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Max: 20
24
+
25
+ Style/MissingRespondToMissing:
26
+ Exclude:
27
+ - 'lib/xmlhasher.rb'
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.2.3
6
5
  - 2.3.0
7
6
  - 2.5.1
7
+ - 2.6.3
8
8
  script:
9
9
  - gem build xmlhasher.gemspec
10
10
  - gem install xmlhasher-*
@@ -0,0 +1,71 @@
1
+ # Changelog
2
+
3
+ All changes to the XmlHasher gem are documented here. Releases follow semantic versioning.
4
+
5
+ ## [1.0.5] - 2019-06-16
6
+
7
+ - Updated ox version.
8
+ - Fixed warning for global variable `$INPUT_RECORD_SEPARATOR`.
9
+ - CHANGELOG.md added.
10
+ - Use new ruby style guide and `rubocop` gem.
11
+ - Added transform cache for keys.
12
+
13
+ ## [1.0.4] - 2018-09-20
14
+
15
+ - Added `rake benchmark` command.
16
+ - Enabled CDATA parsing.
17
+ - Cleanup travis config.
18
+ - Updated ox version.
19
+
20
+ ## [1.0.3] - 2018-09-20
21
+
22
+ - Updated ruby version requirement.
23
+ - Fix deprecation warning on SimpleCov::Formatter::MultiFormatter use.
24
+ - Update dependencies.
25
+
26
+ ## [1.0.2] - 2016-02-20
27
+
28
+ - Cleaned up support environments.
29
+ - Updated ruby version requirement.
30
+
31
+ ## [1.0.1] - 2016-02-20
32
+
33
+ - Bumped OX and escape_utils gem dependency versions.
34
+
35
+
36
+ ## [1.0.0] - 2016-02-20
37
+
38
+ - Small changes in README.md.
39
+ - Removed roby-head from Travis - too unstable.
40
+ - Fixed ruby 2.2+ issue with single node parsing.
41
+
42
+ ## [0.0.6] - 2013-09-09
43
+
44
+ - Added script for benchmarks.
45
+ - Added 'string_keys' option to keep keys at Strings vs Symbols.
46
+
47
+ ## [0.0.5] - 2013-04-24
48
+
49
+ - Test release (CI).
50
+
51
+ ## [0.0.4] - 2013-04-24
52
+
53
+ - Fixed mixed children array detection.
54
+ - Enable Coveralls.
55
+ - Add more examples and license into README.md
56
+
57
+ ## [0.0.3] - 2013-04-24
58
+
59
+ - Added escape method for attributes and dependency from `escape_utils` gem.
60
+ - Some fixes for node children parsing.
61
+ - Added more tests.
62
+
63
+ ## [0.0.2] - 2013-04-24
64
+
65
+ - Some fixes for node children parsing.
66
+ - Add more tests.
67
+ - Updated gem description.
68
+
69
+ ## [0.0.1] - 2013-04-24
70
+
71
+ - The first implementation of the XML parser.
data/Gemfile CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
7
  group :test do
8
+ gem 'coveralls', require: false
6
9
  gem 'minitest'
10
+ gem 'simplecov', require: false
7
11
  gem 'test-unit'
8
- gem 'simplecov', :require => false
9
- gem 'coveralls', :require => false
10
- end
12
+ 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
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,9 +9,9 @@ Rake::TestTask.new(:test) do |t|
7
9
  t.verbose = true
8
10
  end
9
11
 
10
- desc "Run the benchmarks"
12
+ desc 'Run the benchmarks'
11
13
  task :benchmark do
12
- system("ruby", File.join(File.dirname(__FILE__), "benchmark", "benchmark.rb"))
14
+ system('ruby', File.join(File.dirname(__FILE__), 'benchmark', 'benchmark.rb'))
13
15
  end
14
16
 
15
- task :default => :test
17
+ task default: :test
@@ -1,4 +1,6 @@
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'
@@ -28,7 +30,6 @@ rescue LoadError
28
30
  puts "libxml gem in not installed, run 'gem install libxml-ruby'"
29
31
  end
30
32
 
31
-
32
33
  def benchmark(runs, xml)
33
34
  label_width = 25 # needs to be >= any label's size
34
35
 
@@ -53,7 +54,7 @@ def benchmark(runs, xml)
53
54
  end
54
55
 
55
56
  x.report 'nori' do
56
- runs.times { Nori.new(:advanced_typecasting => false).parse(xml) }
57
+ runs.times { Nori.new(advanced_typecasting: false).parse(xml) }
57
58
  end
58
59
 
59
60
  x.report 'xmlhasher' do
@@ -63,7 +64,7 @@ def benchmark(runs, xml)
63
64
  end
64
65
 
65
66
  puts 'Converting small xml from text to Hash:'
66
- benchmark(100, File.read(File.expand_path('../../test/fixtures/institution.xml', __FILE__)))
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(5, File.read(File.expand_path('../../test/fixtures/institutions.xml', __FILE__)))
69
+ benchmark(5, File.read(File.expand_path('../test/fixtures/institutions.xml', __dir__)))
69
70
  puts
data/bin/rake CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  #
4
5
  # This file was generated by Bundler.
5
6
  #
@@ -7,11 +8,10 @@
7
8
  # this file is here to facilitate running it.
8
9
  #
9
10
 
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
13
13
 
14
- require "rubygems"
15
- require "bundler/setup"
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
16
 
17
- load Gem.bin_path("rake", "rake")
17
+ load Gem.bin_path('rake', 'rake')
@@ -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,8 @@ 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
-
23
25
  end
24
-
25
26
  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,7 @@ 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({}) { |key, hash| hash[key] = instance_variable_get(:"@#{key}"); }
17
18
  end
18
-
19
19
  end
20
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ox'
2
4
  require 'escape_utils'
3
5
 
@@ -6,6 +8,7 @@ module XmlHasher
6
8
  def initialize(options = {})
7
9
  @options = options
8
10
  @stack = []
11
+ @transform_cache = {}
9
12
  end
10
13
 
11
14
  def to_hash
@@ -17,9 +20,9 @@ module XmlHasher
17
20
  end
18
21
 
19
22
  def attr(name, value)
20
- unless ignore_attribute?(name)
21
- @stack.last.attributes[transform(name)] = escape(value) unless @stack.empty?
22
- end
23
+ return if ignore_attribute?(name) || @stack.empty?
24
+
25
+ @stack.last.attributes[transform(name)] = escape(value)
23
26
  end
24
27
 
25
28
  def text(value)
@@ -30,7 +33,7 @@ module XmlHasher
30
33
  @stack.last.text = escape(str)
31
34
  end
32
35
 
33
- def end_element(name)
36
+ def end_element(_name)
34
37
  if @stack.size == 1
35
38
  @hash = @stack.pop.to_hash
36
39
  else
@@ -42,9 +45,14 @@ module XmlHasher
42
45
  private
43
46
 
44
47
  def transform(name)
48
+ return @transform_cache[name] if @transform_cache[name]
49
+
50
+ orig_name = name
51
+
45
52
  name = name.to_s.split(':').last if @options[:ignore_namespaces]
46
53
  name = Util.snakecase(name) if @options[:snakecase]
47
54
  name = name.to_sym unless @options[:string_keys]
55
+ @transform_cache[orig_name] = name
48
56
  name
49
57
  end
50
58
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module XmlHasher
2
4
  class Node
3
5
  attr_accessor :name, :attributes, :children, :text
@@ -13,11 +15,11 @@ module XmlHasher
13
15
  if text && !text.empty?
14
16
  h[name] = text
15
17
  else
16
- h[name] = attributes.inject({}) { |r, (key, value)| r[key] = value if !value.nil? && !value.to_s.empty?; r }
18
+ h[name] = attributes.each_with_object({}) { |(key, value), r| r[key] = value if !value.nil? && !value.to_s.empty?; }
17
19
  if children.size == 1
18
20
  h[name].merge!(children.first.to_hash)
19
21
  else
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 })
22
+ h[name].merge!(children.group_by(&:name).each_with_object({}) { |(k, v), r| v.length == 1 ? r.merge!(v.first.to_hash) : r[k] = v.map { |c| c.to_hash[c.name] }; })
21
23
  end
22
24
  end
23
25
  h[name] = nil if h[name].empty?
@@ -25,4 +27,3 @@ module XmlHasher
25
27
  end
26
28
  end
27
29
  end
28
-
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
 
3
5
  module XmlHasher
4
6
  class Parser
5
-
6
7
  def initialize(options = {})
7
8
  @options = options
8
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module XmlHasher
2
4
  module Util
3
5
  def self.snakecase(str)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module XmlHasher
2
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
3
5
  end
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'xmlhasher/version'
5
6
 
@@ -8,25 +9,26 @@ Gem::Specification.new do |spec|
8
9
  spec.version = XmlHasher::VERSION
9
10
  spec.authors = ['Gene Drabkin']
10
11
  spec.email = ['gene.drabkin@gmail.com']
11
- spec.description = %q{Fast XML to Ruby Hash converter}
12
- spec.summary = %q{XmlHasher converts XML to Ruby Hash}
12
+ spec.description = 'Fast XML to Ruby Hash converter'
13
+ spec.summary = 'XmlHasher converts XML to Ruby Hash'
13
14
  spec.homepage = 'https://github.com/cloocher/xmlhasher'
14
15
  spec.license = 'MIT'
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
18
20
  spec.require_paths = ['lib']
19
21
 
20
- spec.required_ruby_version = '>= 1.9.3'
22
+ spec.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
21
23
  spec.required_rubygems_version = '>= 1.3.6'
22
24
 
23
- spec.add_dependency 'ox', '~> 2.10.0'
24
25
  spec.add_dependency 'escape_utils', '~> 1.2'
26
+ spec.add_dependency 'ox', '~> 2.11.0'
25
27
 
26
- spec.add_development_dependency 'rake'
27
28
  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
29
  spec.add_development_dependency 'coveralls', '~> 0.8.21'
30
+ spec.add_development_dependency 'minitest', '~> 5.10'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'simplecov', '~> 0.14.1'
33
+ spec.add_development_dependency 'test-unit', '~> 3.2'
32
34
  end
metadata CHANGED
@@ -1,45 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlhasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene Drabkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ox
14
+ name: escape_utils
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.10.0
19
+ version: '1.2'
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
- version: 2.10.0
26
+ version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: escape_utils
28
+ name: ox
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.2'
33
+ version: 2.11.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.2'
40
+ version: 2.11.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.8.21
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.8.21
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5.10'
83
83
  - !ruby/object:Gem::Dependency
84
- name: test-unit
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '3.2'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '3.2'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,19 +109,19 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.14.1
111
111
  - !ruby/object:Gem::Dependency
112
- name: coveralls
112
+ name: test-unit
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.8.21
117
+ version: '3.2'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.8.21
124
+ version: '3.2'
125
125
  description: Fast XML to Ruby Hash converter
126
126
  email:
127
127
  - gene.drabkin@gmail.com
@@ -130,9 +130,11 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
+ - ".rubocop.yml"
133
134
  - ".ruby-gemset"
134
135
  - ".ruby-version"
135
136
  - ".travis.yml"
137
+ - CHANGELOG.md
136
138
  - Gemfile
137
139
  - LICENSE.txt
138
140
  - README.md
@@ -146,11 +148,6 @@ files:
146
148
  - lib/xmlhasher/parser.rb
147
149
  - lib/xmlhasher/util.rb
148
150
  - lib/xmlhasher/version.rb
149
- - test/fixtures/institution.xml
150
- - test/fixtures/institutions.xml
151
- - test/test_helper.rb
152
- - test/xmlhasher/parser_test.rb
153
- - test/xmlhasher/xmlhasher_test.rb
154
151
  - xmlhasher.gemspec
155
152
  homepage: https://github.com/cloocher/xmlhasher
156
153
  licenses:
@@ -176,9 +173,4 @@ rubygems_version: 2.7.6
176
173
  signing_key:
177
174
  specification_version: 4
178
175
  summary: XmlHasher converts XML to Ruby Hash
179
- test_files:
180
- - test/fixtures/institution.xml
181
- - test/fixtures/institutions.xml
182
- - test/test_helper.rb
183
- - test/xmlhasher/parser_test.rb
184
- - test/xmlhasher/xmlhasher_test.rb
176
+ test_files: []