nori 2.2.0 → 2.3.0

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
  SHA1:
3
- metadata.gz: 3e19155f25d041f2c528280d6985a66128069105
4
- data.tar.gz: a0446834296e76ef56b850fda6d40f455c10bf3f
3
+ metadata.gz: 7a4585ff58e2073a1108c7961be22c7f3caf5c80
4
+ data.tar.gz: b9ab6223657d1839d7a2e4553b7d5a84452bf4c7
5
5
  SHA512:
6
- metadata.gz: acdcd81ae0503f8efb3bfbba9975c7c686b3913ca570f7e3b037bd8625517e8be1918e1943223681563222ca6621db655d91423d8f80cd9ad17d979e8d4cf33e
7
- data.tar.gz: 3e898eedb82cc8d3fe3041f69c3e2879522c9112bddd508da6c704374f652e3ccf05cdab511fa0d2ff881155cad6aee82eacac909af2f058a9ea503dc48b02f4
6
+ metadata.gz: 432b9de3992b4d4b16a6bfa2fa2e222dbaf11f478ebac4e1f73f8c565ff8d30952a03ee65d6bdd224fb409c82972340ed25817110aeb6ec396974ff50cb11709
7
+ data.tar.gz: aae0fa14740a20a9f4e5419261a22ad4733da0a2b841e56dbc080bad205f7bfc98a386bb4cf674d8457e20b6e1b7a6c38af9ee4f76b64fb14cd04d4ee1e6d1a5
@@ -1,8 +1,11 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ language: "ruby"
1
3
  script: "bundle exec rake"
2
4
  rvm:
3
5
  - 1.8.7
4
6
  - 1.9.2
5
7
  - 1.9.3
8
+ - 2.0
6
9
  - jruby-18mode
7
10
  - jruby-19mode
8
11
  - rbx-18mode
@@ -1,3 +1,9 @@
1
+ # 2.3.0 (2013-07-26)
2
+
3
+ * Change: `Nori#find` now ignores namespace prefixes in Hash keys it is searching through.
4
+
5
+ * Fix: Limited Nokogiri to < 1.6, because v1.6 dropped support for Ruby 1.8.
6
+
1
7
  # 2.2.0 (2013-04-25)
2
8
 
3
9
  * Feature: [#42](https://github.com/savonrb/nori/pull/42) adds the `:delete_namespace_attributes`
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
- Nori [![Build Status](https://secure.travis-ci.org/savonrb/nori.png)](http://travis-ci.org/savonrb/nori)
1
+ Nori
2
2
  ====
3
3
 
4
+ [![Build Status](https://secure.travis-ci.org/savonrb/nori.png)](http://travis-ci.org/savonrb/nori)
5
+ [![Gem Version](https://badge.fury.io/rb/nori.png)](http://badge.fury.io/rb/nori)
6
+ [![Code Climate](https://codeclimate.com/github/savonrb/nori.png)](https://codeclimate.com/github/savonrb/nori)
7
+ [![Coverage Status](https://coveralls.io/repos/savonrb/nori/badge.png?branch=master)](https://coveralls.io/r/savonrb/nori)
8
+
9
+
4
10
  Really simple XML parsing ripped from Crack which ripped it from Merb.
5
11
  Nori was created to bypass the stale development of Crack, improve its XML parser
6
12
  and fix certain issues.
@@ -12,10 +18,10 @@ parser.parse("<tag>This is the contents</tag>")
12
18
  ```
13
19
 
14
20
  Nori supports pluggable parsers and ships with both REXML and Nokogiri implementations.
15
- It defaults to REXML, but you can change it to use Nokogiri via:
21
+ It defaults to Nokogiri since v2.0.0, but you can change it to use REXML via:
16
22
 
17
23
  ``` ruby
18
- Nori.new(:parser => :nokogiri) # or :rexml
24
+ Nori.new(:parser => :rexml) # or :nokogiri
19
25
  ```
20
26
 
21
27
  Make sure Nokogiri is in your LOAD_PATH when parsing XML, because Nori tries to load it
@@ -9,11 +9,11 @@ Benchmark.bm 30 do |x|
9
9
  xml = File.read File.expand_path("../soap_response.xml", __FILE__)
10
10
 
11
11
  x.report "rexml parser" do
12
- num.times { Nori.parse xml, :rexml }
12
+ num.times { Nori.new(parser: :rexml).parse xml }
13
13
  end
14
14
 
15
15
  x.report "nokogiri parser" do
16
- num.times { Nori.parse xml, :nokogiri }
16
+ num.times { Nori.new(parser: :nokogiri).parse xml }
17
17
  end
18
18
 
19
19
  end
@@ -32,8 +32,8 @@ class Nori
32
32
  key = path.shift
33
33
  key = self.class.hash_key(key, @options)
34
34
 
35
- return nil unless hash.include? key
36
- find(hash[key], *path)
35
+ value = find_value(hash, key)
36
+ find(value, *path) if value
37
37
  end
38
38
 
39
39
  def parse(xml)
@@ -60,4 +60,13 @@ class Nori
60
60
  end
61
61
  end
62
62
 
63
+ def find_value(hash, key)
64
+ hash.each do |k, v|
65
+ key_without_namespace = k.to_s.split(':').last
66
+ return v if key_without_namespace == key.to_s
67
+ end
68
+
69
+ nil
70
+ end
71
+
63
72
  end
@@ -1,4 +1,6 @@
1
1
  require "rexml/parsers/baseparser"
2
+ require "rexml/text"
3
+ require "rexml/document"
2
4
 
3
5
  class Nori
4
6
  module Parser
@@ -13,7 +15,7 @@ class Nori
13
15
  parser = ::REXML::Parsers::BaseParser.new(xml)
14
16
 
15
17
  while true
16
- event = parser.pull
18
+ event = unnormalize(parser.pull)
17
19
  case event[0]
18
20
  when :end_document
19
21
  break
@@ -32,7 +34,18 @@ class Nori
32
34
  end
33
35
  stack.length > 0 ? stack.pop.to_hash : {}
34
36
  end
35
- end
36
37
 
38
+ def self.unnormalize(event)
39
+ event.map! do |el|
40
+ if el.is_a?(String)
41
+ ::REXML::Text.unnormalize(el)
42
+ elsif el.is_a?(Hash)
43
+ el.each {|k,v| el[k] = ::REXML::Text.unnormalize(v)}
44
+ else
45
+ el
46
+ end
47
+ end
48
+ end
49
+ end
37
50
  end
38
51
  end
@@ -1,5 +1,5 @@
1
1
  class Nori
2
2
 
3
- VERSION = "2.2.0"
3
+ VERSION = "2.3.0"
4
4
 
5
5
  end
@@ -1,5 +1,3 @@
1
- require "rexml/text"
2
- require "rexml/document"
3
1
  require "date"
4
2
  require "time"
5
3
  require "yaml"
@@ -83,12 +81,7 @@ class Nori
83
81
 
84
82
  self.available_typecasts = self.typecasts.keys
85
83
 
86
- def initialize(options, name, normalized_attributes = {})
87
- # unnormalize attribute values
88
- attributes = Hash[* normalized_attributes.map do |key, value|
89
- [ key, unnormalize_xml_entities(value) ]
90
- end.flatten]
91
-
84
+ def initialize(options, name, attributes = {})
92
85
  @options = options
93
86
  @name = Nori.hash_key(name, options)
94
87
 
@@ -136,7 +129,7 @@ class Nori
136
129
  end
137
130
 
138
131
  if @text
139
- t = typecast_value unnormalize_xml_entities(inner_html)
132
+ t = typecast_value(inner_html)
140
133
  t = advanced_typecasting(t) if t.is_a?(String) && @options[:advanced_typecasting]
141
134
 
142
135
  if t.is_a?(String)
@@ -250,11 +243,6 @@ class Nori
250
243
 
251
244
  private
252
245
 
253
- # TODO: replace REXML
254
- def unnormalize_xml_entities value
255
- REXML::Text.unnormalize(value)
256
- end
257
-
258
246
  def try_to_convert(value, &block)
259
247
  block.call(value)
260
248
  rescue ArgumentError
@@ -12,9 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.description = s.summary
13
13
 
14
14
  s.rubyforge_project = "nori"
15
+ s.license = "MIT"
15
16
 
16
17
  s.add_development_dependency "rake", "~> 10.0"
17
- s.add_development_dependency "nokogiri", ">= 1.4.0"
18
+ s.add_development_dependency "nokogiri", ">= 1.4.0", "< 1.6"
18
19
  s.add_development_dependency "rspec", "~> 2.12"
19
20
 
20
21
  s.files = `git ls-files`.split("\n")
@@ -85,6 +85,14 @@ describe Nori do
85
85
  result = @nori.find(@hash, 'userResponse', 'accountStatus')
86
86
  expect(result).to eq("active")
87
87
  end
88
+
89
+ it 'strips the namespaces from Hash keys' do
90
+ xml = '<v1:userResponse xmlns:v1="http://example.com"><v1:accountStatus>active</v1:accountStatus></v1:userResponse>'
91
+ hash = @nori.parse(xml)
92
+
93
+ result = @nori.find(hash, 'userResponse', 'accountStatus')
94
+ expect(result).to eq("active")
95
+ end
88
96
  end
89
97
 
90
98
  context "#parse" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nori
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-25 00:00:00.000000000 Z
13
+ date: 2013-07-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -33,6 +33,9 @@ dependencies:
33
33
  - - '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.4.0
36
+ - - <
37
+ - !ruby/object:Gem::Version
38
+ version: '1.6'
36
39
  type: :development
37
40
  prerelease: false
38
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -40,6 +43,9 @@ dependencies:
40
43
  - - '>='
41
44
  - !ruby/object:Gem::Version
42
45
  version: 1.4.0
46
+ - - <
47
+ - !ruby/object:Gem::Version
48
+ version: '1.6'
43
49
  - !ruby/object:Gem::Dependency
44
50
  name: rspec
45
51
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +95,8 @@ files:
89
95
  - spec/nori/nori_spec.rb
90
96
  - spec/spec_helper.rb
91
97
  homepage: https://github.com/savonrb/nori
92
- licenses: []
98
+ licenses:
99
+ - MIT
93
100
  metadata: {}
94
101
  post_install_message:
95
102
  rdoc_options: []
@@ -107,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
114
  version: '0'
108
115
  requirements: []
109
116
  rubyforge_project: nori
110
- rubygems_version: 2.0.3
117
+ rubygems_version: 2.0.6
111
118
  signing_key:
112
119
  specification_version: 4
113
120
  summary: XML to Hash translator