xmlhasher 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,23 +1,58 @@
1
1
  # XmlHasher
2
2
 
3
3
  [![Build Status](https://travis-ci.org/cloocher/xmlhasher.png)](https://travis-ci.org/cloocher/xmlhasher)
4
+ [![Coverage Status](https://coveralls.io/repos/cloocher/xmlhasher/badge.png?branch=master)](https://coveralls.io/r/cloocher/xmlhasher)
5
+ [![Gem Version](https://badge.fury.io/rb/xmlhasher.png)](http://badge.fury.io/rb/xmlhasher)
4
6
 
5
- Xml to Ruby Hash converter
7
+ Fast XML to Ruby Hash converter
6
8
 
7
9
  ## Installation
8
10
 
9
- Add this line to your application's Gemfile:
10
-
11
- gem 'xmlhasher'
11
+ ## Installation
12
12
 
13
- And then execute:
13
+ Aggcat is available through [Rubygems](http://rubygems.org/gems/xmlhasher) and can be installed via:
14
14
 
15
- $ bundle
15
+ ```
16
+ $ gem install xmlhasher
17
+ ```
16
18
 
17
- Or install it yourself as:
19
+ or add it to your Gemfile like this:
18
20
 
19
- $ gem install xmlhasher
21
+ ```
22
+ gem 'xmlhasher'
23
+ ```
20
24
 
21
25
  ## Usage
22
26
 
23
- TODO: Write usage instructions here
27
+ ```ruby
28
+ require 'xmlhasher'
29
+
30
+ # XmlHasher global configuration
31
+ XmlHasher.configure do |config|
32
+ config.snakecase = true
33
+ config.ignore_namespaces = true
34
+ end
35
+
36
+ # alternatively, specify configuration options when instantiating a Parser
37
+ parser = XmlHasher::Parser.new(
38
+ :snakecase => true,
39
+ :ignore_namespaces => true
40
+ )
41
+
42
+ # parse XML file
43
+ XmlHasher.parse(File.new('/path/to/my/file.xml'))
44
+
45
+ # parse XML string
46
+ XmlHasher.parse("<tag1><tag2>content</tag2></tag1>")
47
+ # => {:tag1=>{:tag2=>"content"}}
48
+
49
+ ```
50
+ ## Requirements
51
+
52
+ * Ruby 1.8.7 or higher
53
+
54
+ ## Copyright
55
+ Copyright (c) 2013 Gene Drabkin.
56
+ See [LICENSE][] for details.
57
+
58
+ [license]: LICENSE.md
@@ -18,11 +18,7 @@ module XmlHasher
18
18
  child = children.first
19
19
  h[name].merge!(child.to_hash)
20
20
  else
21
- if children.map(&:name).uniq.size == 1
22
- h[name].merge!(children.inject({}) { |r, child| (r[child.name] ||= []) << child.to_hash[child.name]; r })
23
- else
24
- h[name].merge!(children.inject({}) { |r, child| r.merge!(child.to_hash); r })
25
- end
21
+ h[name].merge!(children.group_by { |child| child.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 })
26
22
  end
27
23
  end
28
24
  h[name] = nil if h[name].empty?
@@ -1,3 +1,3 @@
1
1
  module XmlHasher
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/test/test_helper.rb CHANGED
@@ -9,6 +9,7 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
9
  Coveralls::SimpleCov::Formatter
10
10
  ]
11
11
  SimpleCov.start
12
+ Coveralls.wear!
12
13
 
13
14
  require 'test/unit'
14
15
  require 'xmlhasher'
@@ -196,6 +196,12 @@ class XmlhasherTest < Test::Unit::TestCase
196
196
  assert_equal expected, XmlHasher::Parser.new.parse(xml)
197
197
  end
198
198
 
199
+ def test_array_detection_with_mixed_children
200
+ xml = %[<tag><tag2 attr='1' /><tag3>content</tag3><tag2 attr='2' /></tag>]
201
+ expected = {:tag => {:tag2 => [{:attr => '1'}, {:attr => '2'}], :tag3 => 'content'}}
202
+ assert_equal expected, XmlHasher::Parser.new.parse(xml)
203
+ end
204
+
199
205
  def test_single_child
200
206
  xml = %[<tag><tag2 attr='1' /></tag>]
201
207
  expected = {:tag => {:tag2 => {:attr => '1'}}}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlhasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: