nori 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +6 -0
- data/README.md +9 -3
- data/benchmark/benchmark.rb +2 -2
- data/lib/nori.rb +11 -2
- data/lib/nori/parser/rexml.rb +15 -2
- data/lib/nori/version.rb +1 -1
- data/lib/nori/xml_utility_node.rb +2 -14
- data/nori.gemspec +2 -1
- data/spec/nori/api_spec.rb +8 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a4585ff58e2073a1108c7961be22c7f3caf5c80
|
4
|
+
data.tar.gz: b9ab6223657d1839d7a2e4553b7d5a84452bf4c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 432b9de3992b4d4b16a6bfa2fa2e222dbaf11f478ebac4e1f73f8c565ff8d30952a03ee65d6bdd224fb409c82972340ed25817110aeb6ec396974ff50cb11709
|
7
|
+
data.tar.gz: aae0fa14740a20a9f4e5419261a22ad4733da0a2b841e56dbc080bad205f7bfc98a386bb4cf674d8457e20b6e1b7a6c38af9ee4f76b64fb14cd04d4ee1e6d1a5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
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
|
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 => :
|
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
|
data/benchmark/benchmark.rb
CHANGED
@@ -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
|
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
|
16
|
+
num.times { Nori.new(parser: :nokogiri).parse xml }
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
data/lib/nori.rb
CHANGED
@@ -32,8 +32,8 @@ class Nori
|
|
32
32
|
key = path.shift
|
33
33
|
key = self.class.hash_key(key, @options)
|
34
34
|
|
35
|
-
|
36
|
-
find(
|
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
|
data/lib/nori/parser/rexml.rb
CHANGED
@@ -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
|
data/lib/nori/version.rb
CHANGED
@@ -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,
|
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
|
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
|
data/nori.gemspec
CHANGED
@@ -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")
|
data/spec/nori/api_spec.rb
CHANGED
@@ -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.
|
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-
|
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.
|
117
|
+
rubygems_version: 2.0.6
|
111
118
|
signing_key:
|
112
119
|
specification_version: 4
|
113
120
|
summary: XML to Hash translator
|