xml2json 0.4.4 → 0.4.5
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 +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +5 -0
- data/README.md +1 -1
- data/Rakefile +6 -0
- data/lib/xml2json.rb +2 -11
- data/lib/xml2json/configuration.rb +9 -0
- data/lib/xml2json/version.rb +1 -1
- data/spec/xml2json_spec.rb +19 -12
- data/xml2json.gemspec +2 -1
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21d104b9244a5fb10324e6682a639c7a067e0b42
|
4
|
+
data.tar.gz: bbdb5b6fd3edad22b522ee7e73c1b9f4829f139d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fc5074758d79c43bf7ea43fb1116736a2209362cae89f0c78cd06ba032ddd3fe80acee8edb9584cab08e32744a25b15ec23f98f915d36e9421f71ad54dc75e
|
7
|
+
data.tar.gz: 4ed364926a5fc79574412bf5fcedebc4aa18b3242be82b95d1a359135ec318f4da5f011edd656f8b693357291d2fab122715f9937b3d790b199366fd748bf267
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.2
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# xml2json
|
2
2
|
|
3
|
-
[](https://codeclimate.com/github/monksoftware/xml2json) [](http://badge.fury.io/rb/xml2json)
|
3
|
+
[](https://codeclimate.com/github/monksoftware/xml2json) [](http://badge.fury.io/rb/xml2json) [](https://gemnasium.com/monksoftware/xml2json) [](https://travis-ci.org/monksoftware/xml2json)
|
4
4
|
|
5
5
|
Transforms XML into JSON
|
6
6
|
|
data/Rakefile
ADDED
data/lib/xml2json.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'json'
|
3
3
|
require 'active_support/inflector'
|
4
|
+
require_relative './xml2json/configuration'
|
4
5
|
|
5
6
|
module XML2JSON
|
6
7
|
class InvalidXML < StandardError; end
|
@@ -47,7 +48,7 @@ module XML2JSON
|
|
47
48
|
|
48
49
|
if hash.has_key?(key)
|
49
50
|
node_to_nodes!(hash, child)
|
50
|
-
hash.delete(key)
|
51
|
+
hash.delete(key) unless key == pluralized_key
|
51
52
|
hash[pluralized_key] << parse_node(child)
|
52
53
|
else
|
53
54
|
if hash.has_key?(pluralized_key)
|
@@ -81,16 +82,6 @@ module XML2JSON
|
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
84
|
-
class Configuration
|
85
|
-
attr_accessor :attributes_key, :namespaces_key, :text_key
|
86
|
-
|
87
|
-
def initialize
|
88
|
-
self.attributes_key = '_attributes'
|
89
|
-
self.namespaces_key = '_namespaces'
|
90
|
-
self.text_key = '_text'
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
85
|
def self.configuration
|
95
86
|
@configuration ||= Configuration.new
|
96
87
|
end
|
data/lib/xml2json/version.rb
CHANGED
data/spec/xml2json_spec.rb
CHANGED
@@ -41,19 +41,19 @@ describe XML2JSON do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "handles multiple elements" do
|
44
|
-
xml = '<a><x><b>
|
44
|
+
xml = '<a><x><b>First</b><b>Second</b></x></a>'
|
45
45
|
expect(XML2JSON.parse_to_hash(xml)).to(
|
46
|
-
eq({ "a" => { "x" => { "bs" => [ "
|
46
|
+
eq({ "a" => { "x" => { "bs" => [ "First", "Second" ] } } })
|
47
47
|
)
|
48
48
|
|
49
|
-
xml = '<a><b><x>
|
49
|
+
xml = '<a><b><x>First</x></b><b><x>Second</x></b></a>'
|
50
50
|
expect(XML2JSON.parse_to_hash(xml)).to(
|
51
|
-
eq({ "a" => { "bs" => [ { "x" => "
|
51
|
+
eq({ "a" => { "bs" => [ { "x" => "First" }, { "x" => "Second" } ] } })
|
52
52
|
)
|
53
53
|
|
54
|
-
xml = '<a><b><x>
|
54
|
+
xml = '<a><b><x>First</x></b><b><x>Second</x></b><b><x>Third</x></b></a>'
|
55
55
|
expect(XML2JSON.parse_to_hash(xml)).to(
|
56
|
-
eq({ "a" => { "bs" => [ { "x" => "
|
56
|
+
eq({ "a" => { "bs" => [ { "x" => "First" }, { "x" => "Second" }, { "x" => "Third" }] } })
|
57
57
|
)
|
58
58
|
end
|
59
59
|
|
@@ -63,9 +63,9 @@ describe XML2JSON do
|
|
63
63
|
eq({"r" => {"a" => { "_attributes" => {"url" => "www.google.it"}}}})
|
64
64
|
)
|
65
65
|
|
66
|
-
xml = '<r><a url="www.google.it"><b>
|
66
|
+
xml = '<r><a url="www.google.it"><b>Hello</b></a></r>'
|
67
67
|
expect(XML2JSON.parse_to_hash(xml)).to(
|
68
|
-
eq({"r" => {"a" => { "_attributes" => {"url" => "www.google.it"}, "b" => "
|
68
|
+
eq({"r" => {"a" => { "_attributes" => {"url" => "www.google.it"}, "b" => "Hello"}}})
|
69
69
|
)
|
70
70
|
|
71
71
|
xml = '<r><a url="www.google.it"></a><a url="www.google.com"></a></r>'
|
@@ -73,9 +73,9 @@ describe XML2JSON do
|
|
73
73
|
eq({"r" => {"as" => [{ "_attributes" => {"url" => "www.google.it"}},{ "_attributes" => {"url" => "www.google.com"}}]}})
|
74
74
|
)
|
75
75
|
|
76
|
-
xml = '<r><a url="www.google.it"><b>
|
76
|
+
xml = '<r><a url="www.google.it"><b>Hello</b></a><a url="www.google.com"><b>Hello</b></a></r>'
|
77
77
|
expect(XML2JSON.parse_to_hash(xml)).to(
|
78
|
-
eq({"r" => {"as" => [{ "_attributes" => {"url" => "www.google.it"}, "b" => "
|
78
|
+
eq({"r" => {"as" => [{ "_attributes" => {"url" => "www.google.it"}, "b" => "Hello"},{ "_attributes" => {"url" => "www.google.com"}, "b" => "Hello"}]}})
|
79
79
|
)
|
80
80
|
end
|
81
81
|
|
@@ -118,9 +118,16 @@ describe XML2JSON do
|
|
118
118
|
|
119
119
|
context "pluralize" do
|
120
120
|
it "pluralizes keys name when multiple nodes" do
|
121
|
-
xml = '<root><item>
|
121
|
+
xml = '<root><item>First</item><item>Second</item></root>'
|
122
122
|
expect(XML2JSON.parse_to_hash(xml)).to(
|
123
|
-
eq({ "root" => { "items" => [ "
|
123
|
+
eq({ "root" => { "items" => [ "First", "Second"] } })
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "works with already plural keys names" do
|
128
|
+
xml = '<root><items>First</items><items>Second</items></root>'
|
129
|
+
expect(XML2JSON.parse_to_hash(xml)).to(
|
130
|
+
eq({ "root" => { "items" => [ "First", "Second"] } })
|
124
131
|
)
|
125
132
|
end
|
126
133
|
end
|
data/xml2json.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
22
|
spec.add_development_dependency "rspec", "~> 2.14"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
23
24
|
spec.add_dependency "nokogiri", "~> 1.6"
|
24
|
-
spec.add_dependency "activesupport", "~> 4.
|
25
|
+
spec.add_dependency "activesupport", "~> 4.2"
|
25
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml2json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giuseppe Modarelli
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '2.14'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.1'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.1'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: nokogiri
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,14 +73,14 @@ dependencies:
|
|
59
73
|
requirements:
|
60
74
|
- - "~>"
|
61
75
|
- !ruby/object:Gem::Version
|
62
|
-
version: '4.
|
76
|
+
version: '4.2'
|
63
77
|
type: :runtime
|
64
78
|
prerelease: false
|
65
79
|
version_requirements: !ruby/object:Gem::Requirement
|
66
80
|
requirements:
|
67
81
|
- - "~>"
|
68
82
|
- !ruby/object:Gem::Version
|
69
|
-
version: '4.
|
83
|
+
version: '4.2'
|
70
84
|
description: Turn XML into JSON
|
71
85
|
email:
|
72
86
|
- giuseppe.modarelli@gmail.com
|
@@ -78,10 +92,13 @@ files:
|
|
78
92
|
- ".gitignore"
|
79
93
|
- ".ruby-gemset"
|
80
94
|
- ".ruby-version"
|
95
|
+
- ".travis.yml"
|
81
96
|
- Gemfile
|
82
97
|
- Gemfile.lock
|
83
98
|
- README.md
|
99
|
+
- Rakefile
|
84
100
|
- lib/xml2json.rb
|
101
|
+
- lib/xml2json/configuration.rb
|
85
102
|
- lib/xml2json/version.rb
|
86
103
|
- spec/fixtures/atom.json
|
87
104
|
- spec/fixtures/atom.xml
|