xml2json 0.4.4 → 0.4.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
  SHA1:
3
- metadata.gz: c99a07dc793e5b44c80d5b881da7bb9928f00e75
4
- data.tar.gz: 59f76e15d40e937517a4410658923dbc4ab82fb4
3
+ metadata.gz: 21d104b9244a5fb10324e6682a639c7a067e0b42
4
+ data.tar.gz: bbdb5b6fd3edad22b522ee7e73c1b9f4829f139d
5
5
  SHA512:
6
- metadata.gz: 207b147d1b2da7b38458f41f69ee154d7447dacc373fc83255c1506b61036c6c4ea48741d7004eeaa97851eacc1729d9f9df59bd6e31f4721500d86354c791dd
7
- data.tar.gz: d9f4cf5219d558eae10e83cb5c7c3782fe8f73a1a574ba6a9d6f8cc1efd711401dc35aa95971844dbe58fa4136662daa450529d3c4f349170bc6ce4be605daca
6
+ metadata.gz: a6fc5074758d79c43bf7ea43fb1116736a2209362cae89f0c78cd06ba032ddd3fe80acee8edb9584cab08e32744a25b15ec23f98f915d36e9421f71ad54dc75e
7
+ data.tar.gz: 4ed364926a5fc79574412bf5fcedebc4aa18b3242be82b95d1a359135ec318f4da5f011edd656f8b693357291d2fab122715f9937b3d790b199366fd748bf267
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.2
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.1.0
5
+ - 2.0.0
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # xml2json
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/monksoftware/xml2json.png)](https://codeclimate.com/github/monksoftware/xml2json) [![Gem Version](https://badge.fury.io/rb/xml2json.svg)](http://badge.fury.io/rb/xml2json)
3
+ [![Code Climate](https://codeclimate.com/github/monksoftware/xml2json.png)](https://codeclimate.com/github/monksoftware/xml2json) [![Gem Version](https://badge.fury.io/rb/xml2json.svg)](http://badge.fury.io/rb/xml2json) [![Dependency Status](https://gemnasium.com/monksoftware/xml2json.svg)](https://gemnasium.com/monksoftware/xml2json) [![Build Status](https://travis-ci.org/monksoftware/xml2json.svg?branch=master)](https://travis-ci.org/monksoftware/xml2json)
4
4
 
5
5
  Transforms XML into JSON
6
6
 
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => [:spec]
@@ -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
@@ -0,0 +1,9 @@
1
+ class Configuration
2
+ attr_accessor :attributes_key, :namespaces_key, :text_key
3
+
4
+ def initialize
5
+ self.attributes_key = '_attributes'
6
+ self.namespaces_key = '_namespaces'
7
+ self.text_key = '_text'
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module XML2JSON
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
@@ -41,19 +41,19 @@ describe XML2JSON do
41
41
  end
42
42
 
43
43
  it "handles multiple elements" do
44
- xml = '<a><x><b>Primo</b><b>Secondo</b></x></a>'
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" => [ "Primo", "Secondo" ] } } })
46
+ eq({ "a" => { "x" => { "bs" => [ "First", "Second" ] } } })
47
47
  )
48
48
 
49
- xml = '<a><b><x>Primo</x></b><b><x>Secondo</x></b></a>'
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" => "Primo" }, { "x" => "Secondo" } ] } })
51
+ eq({ "a" => { "bs" => [ { "x" => "First" }, { "x" => "Second" } ] } })
52
52
  )
53
53
 
54
- xml = '<a><b><x>Primo</x></b><b><x>Secondo</x></b><b><x>Terzo</x></b></a>'
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" => "Primo" }, { "x" => "Secondo" }, { "x" => "Terzo" }] } })
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>ciao</b></a></r>'
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" => "ciao"}}})
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>ciao</b></a><a url="www.google.com"><b>ciao</b></a></r>'
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" => "ciao"},{ "_attributes" => {"url" => "www.google.com"}, "b" => "ciao"}]}})
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>Primo</item><item>Secondo</item></root>'
121
+ xml = '<root><item>First</item><item>Second</item></root>'
122
122
  expect(XML2JSON.parse_to_hash(xml)).to(
123
- eq({ "root" => { "items" => [ "Primo", "Secondo"] } })
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
@@ -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.1"
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
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: 2014-06-25 00:00:00.000000000 Z
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.1'
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.1'
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