xml_hate 0.8.3.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +1 -1
- data/Gemfile +1 -2
- data/Gemfile.lock +49 -0
- data/lib/xml_hate.rb +0 -3
- data/lib/xml_hate/document.rb +20 -4
- data/lib/xml_hate/node.rb +18 -2
- data/lib/xml_hate/version.rb +1 -1
- data/readme.md +2 -2
- data/spec/spec_helper.rb +3 -0
- data/spec/xml_hate/document_spec.rb +67 -0
- data/xml_hate.gemspec +1 -1
- metadata +73 -95
- data/.rvmrc +0 -55
- data/Guardfile +0 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e77b6e96c739ee1560ebeb9158231ca4dc3fc75
|
4
|
+
data.tar.gz: 0fd62016eaaf3fbde01b39e64ef67f1c3c42d6c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65a5153b5b0fa43018b8ba42d773f476fd9477da4a5de900cd851f5da7dcd6cdb18096f90989709b96e8dbbb78e64a2b56da1e60db222c56f5ff21298b3db48e
|
7
|
+
data.tar.gz: c3b96a173c076287c4975451b36b0b1cdb94ccb18981c8809a60d336e6863dfa5d00f1db96166c1e241f96b638dcbc3d170649d4eaa8ebd48bda7b880e25ea32
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
xml_hate (2.0.0)
|
5
|
+
activesupport
|
6
|
+
hashie
|
7
|
+
xml-simple
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (3.2.12)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
colorize (0.5.8)
|
16
|
+
coveralls (0.6.2)
|
17
|
+
colorize
|
18
|
+
multi_json (~> 1.3)
|
19
|
+
rest-client
|
20
|
+
simplecov (>= 0.7)
|
21
|
+
thor
|
22
|
+
hashie (2.0.2)
|
23
|
+
i18n (0.6.4)
|
24
|
+
mime-types (1.21)
|
25
|
+
minitest (4.6.2)
|
26
|
+
multi_json (1.6.1)
|
27
|
+
rake (10.0.3)
|
28
|
+
rest-client (1.6.7)
|
29
|
+
mime-types (>= 1.16)
|
30
|
+
ruby_gntp (0.3.4)
|
31
|
+
simplecov (0.7.1)
|
32
|
+
multi_json (~> 1.0)
|
33
|
+
simplecov-html (~> 0.7.1)
|
34
|
+
simplecov-html (0.7.1)
|
35
|
+
thor (0.14.6)
|
36
|
+
xml-simple (1.1.2)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
activesupport
|
43
|
+
coveralls
|
44
|
+
hashie
|
45
|
+
minitest
|
46
|
+
rake
|
47
|
+
ruby_gntp
|
48
|
+
xml-simple
|
49
|
+
xml_hate!
|
data/lib/xml_hate.rb
CHANGED
data/lib/xml_hate/document.rb
CHANGED
@@ -4,24 +4,40 @@ require 'active_support/inflector'
|
|
4
4
|
module XmlHate
|
5
5
|
class Document
|
6
6
|
def initialize(xml)
|
7
|
-
@document = XmlSimple.xml_in(xml)
|
7
|
+
@document = lower_case_please(XmlSimple.xml_in(xml))
|
8
8
|
end
|
9
9
|
|
10
10
|
def method_missing(meth, *args, &blk)
|
11
|
-
|
11
|
+
meth = meth.to_s
|
12
|
+
unless @document.has_key?(meth)
|
13
|
+
if @document.has_key?(meth.singularize)
|
14
|
+
meth = meth.singularize
|
15
|
+
else
|
16
|
+
return ''
|
17
|
+
end
|
18
|
+
end
|
12
19
|
objects = pull_the_objects_from_the_xml_document(meth)
|
13
20
|
objects.count == 1 ? objects[0] : objects
|
14
21
|
end
|
15
22
|
|
16
23
|
private
|
17
24
|
|
25
|
+
def lower_case_please hash
|
26
|
+
hash.keys.reduce({}) do |t, key|
|
27
|
+
value = hash[key].is_a?(Hash) ? lower_case_please(hash[key])
|
28
|
+
: hash[key]
|
29
|
+
value = hash[key]
|
30
|
+
t.merge!( { key.to_s.underscore => value } )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
18
34
|
def pull_the_objects_from_the_xml_document(meth)
|
19
35
|
nodes = read_the_matching_nodes_from_the_xml_document(meth)
|
20
36
|
convert_the_hashes_to_objects(nodes)
|
21
37
|
end
|
22
38
|
|
23
39
|
def read_the_matching_nodes_from_the_xml_document(meth)
|
24
|
-
@document[meth
|
40
|
+
@document[meth].map { |n| process_this_top_level_node(n) }
|
25
41
|
end
|
26
42
|
|
27
43
|
def convert_the_hashes_to_objects(objects)
|
@@ -54,7 +70,7 @@ module XmlHate
|
|
54
70
|
def bring_up_single_elements_as_properties(node)
|
55
71
|
get_properties_with_multiple_elements(node).each do |key, value|
|
56
72
|
value.each { |v| process_this_inner_node(v) }
|
57
|
-
node[key] = value[0] if get_the_number_of_elements(value) == 1
|
73
|
+
node[key] = value[0] if get_the_number_of_elements(value) == 1
|
58
74
|
end
|
59
75
|
end
|
60
76
|
|
data/lib/xml_hate/node.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
module XmlHate
|
2
|
+
|
2
3
|
class Node
|
4
|
+
|
5
|
+
attr_reader :_keys
|
6
|
+
|
3
7
|
def initialize(hash)
|
8
|
+
@_keys = []
|
4
9
|
all_items_in_the_hash_that_are_not_nil(hash).each do |k, v|
|
5
|
-
|
10
|
+
@_keys << get_a_valid_property_name(k)
|
11
|
+
form = convert_the_value_to_the_appropriate_form(v)
|
12
|
+
if form.is_a?(Node)
|
13
|
+
keys = form._keys.map { |x| x.to_s.singularize }.uniq
|
14
|
+
if keys.count == 1 && form.send(keys.first.to_sym).is_a?(Array)
|
15
|
+
form = form.send(keys.first.to_sym)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
create_accessor_for k, form
|
6
19
|
end
|
7
20
|
end
|
8
21
|
|
@@ -19,7 +32,7 @@ module XmlHate
|
|
19
32
|
def an_empty_array_for_plurals_or_empty_string_for_singulars(meth)
|
20
33
|
return [] if meth.to_s == meth.to_s.pluralize
|
21
34
|
|
22
|
-
empty_string =
|
35
|
+
empty_string = ''
|
23
36
|
attempt_to_attach_content_singleton_to_the_value empty_string
|
24
37
|
empty_string
|
25
38
|
end
|
@@ -37,6 +50,7 @@ module XmlHate
|
|
37
50
|
name = name.to_s.gsub('-', '_')
|
38
51
|
name = name.gsub('@', '')
|
39
52
|
name = name.gsub(':', '')
|
53
|
+
name = name.underscore
|
40
54
|
name.to_sym
|
41
55
|
end
|
42
56
|
|
@@ -55,5 +69,7 @@ module XmlHate
|
|
55
69
|
rescue
|
56
70
|
end
|
57
71
|
end
|
72
|
+
|
58
73
|
end
|
74
|
+
|
59
75
|
end
|
data/lib/xml_hate/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# XML Hate
|
1
|
+
# XML Hate [![Build Status](https://secure.travis-ci.org/darrencauthon/xml_hate.png?branch=master)](http://travis-ci.org/darrencauthon/xml_hate) [![Coverage Status](https://coveralls.io/repos/darrencauthon/xml_hate/badge.png?branch=master)](https://coveralls.io/r/darrencauthon/xml_hate)
|
2
2
|
|
3
3
|
## Reading XML with my own ten-foot poll.
|
4
4
|
|
@@ -52,4 +52,4 @@ rearden.firstname # "", defaults to empty string if the value cannot be found
|
|
52
52
|
rearden.whatever_i_want # "", see above
|
53
53
|
rearden.addresses.count # 0, returns [] by assuming you want the plural version
|
54
54
|
|
55
|
-
```
|
55
|
+
```
|
data/spec/spec_helper.rb
CHANGED
@@ -233,4 +233,71 @@ DOC
|
|
233
233
|
end
|
234
234
|
|
235
235
|
end
|
236
|
+
|
237
|
+
describe "snake-case the values" do
|
238
|
+
|
239
|
+
describe "a simple example" do
|
240
|
+
|
241
|
+
before do
|
242
|
+
xml = <<DOC
|
243
|
+
<Root>
|
244
|
+
<Car Name="Testing" Color="Blue" BodyColor="Red"/>
|
245
|
+
</Root>
|
246
|
+
DOC
|
247
|
+
@document = XmlHate::Document.new(xml)
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should return the properties as lower-case values" do
|
251
|
+
@document.car.name.must_equal "Testing"
|
252
|
+
@document.car.color.must_equal "Blue"
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should return the underscore" do
|
256
|
+
@document.car.body_color.must_equal "Red"
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
describe "a more complicated example" do
|
262
|
+
|
263
|
+
before do
|
264
|
+
xml = <<DOC
|
265
|
+
<Root>
|
266
|
+
<FancyCar Name="Testing" Color="Blue" BodyColor="Red"/>
|
267
|
+
<FancyCar Name="Testing2" Color="Blue2" BodyColor="Red2"/>
|
268
|
+
</Root>
|
269
|
+
DOC
|
270
|
+
@document = XmlHate::Document.new(xml)
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should return the properties as lower-case values" do
|
274
|
+
@document.fancy_cars[0].name.must_equal "Testing"
|
275
|
+
@document.fancy_cars[0].color.must_equal "Blue"
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "an even more complicated example" do
|
281
|
+
before do
|
282
|
+
xml = <<DOC
|
283
|
+
<Root>
|
284
|
+
<User Id="1234">
|
285
|
+
<Fields>
|
286
|
+
<Field Name="The Test" />
|
287
|
+
<Field Name="Another Test" />
|
288
|
+
</Fields>
|
289
|
+
</User>
|
290
|
+
</Root>
|
291
|
+
DOC
|
292
|
+
@document = XmlHate::Document.new(xml)
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should flatten the fields/fields thing" do
|
296
|
+
@document.user.fields[0].name.must_equal "The Test"
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
236
303
|
end
|
data/xml_hate.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = XmlHate::VERSION
|
8
8
|
s.authors = ["Darren Cauthon"]
|
9
9
|
s.email = ["darren@cauthon.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "http://www.github.com/darrencauthon/xml_hate"
|
11
11
|
s.summary = %q{Handling xml with my own ten-foot poll.}
|
12
12
|
s.description = %q{xml handling without the xml.}
|
13
13
|
|
metadata
CHANGED
@@ -1,94 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml_hate
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
- 3
|
10
|
-
- 4
|
11
|
-
version: 0.8.3.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
12
5
|
platform: ruby
|
13
|
-
authors:
|
6
|
+
authors:
|
14
7
|
- Darren Cauthon
|
15
8
|
autorequire:
|
16
9
|
bindir: bin
|
17
10
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: xml-simple
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
33
20
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: hashie
|
37
21
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
47
34
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: activesupport
|
51
35
|
prerelease: false
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
61
48
|
type: :runtime
|
62
|
-
version_requirements: *id003
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: rake
|
65
49
|
prerelease: false
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
75
62
|
type: :development
|
76
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
77
69
|
description: xml handling without the xml.
|
78
|
-
email:
|
70
|
+
email:
|
79
71
|
- darren@cauthon.com
|
80
72
|
executables: []
|
81
|
-
|
82
73
|
extensions: []
|
83
|
-
|
84
74
|
extra_rdoc_files: []
|
85
|
-
|
86
|
-
files:
|
75
|
+
files:
|
87
76
|
- .gitignore
|
88
|
-
- .rvmrc
|
89
77
|
- .travis.yml
|
90
78
|
- Gemfile
|
91
|
-
-
|
79
|
+
- Gemfile.lock
|
92
80
|
- Rakefile
|
93
81
|
- lib/xml_hate.rb
|
94
82
|
- lib/xml_hate/document.rb
|
@@ -99,40 +87,30 @@ files:
|
|
99
87
|
- spec/xml_hate/document_spec.rb
|
100
88
|
- spec/xml_hate/node_spec.rb
|
101
89
|
- xml_hate.gemspec
|
102
|
-
homepage:
|
90
|
+
homepage: http://www.github.com/darrencauthon/xml_hate
|
103
91
|
licenses: []
|
104
|
-
|
92
|
+
metadata: {}
|
105
93
|
post_install_message:
|
106
94
|
rdoc_options: []
|
107
|
-
|
108
|
-
require_paths:
|
95
|
+
require_paths:
|
109
96
|
- lib
|
110
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
none: false
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
hash: 3
|
125
|
-
segments:
|
126
|
-
- 0
|
127
|
-
version: "0"
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
128
107
|
requirements: []
|
129
|
-
|
130
108
|
rubyforge_project: xml_hate
|
131
|
-
rubygems_version:
|
109
|
+
rubygems_version: 2.4.5
|
132
110
|
signing_key:
|
133
|
-
specification_version:
|
111
|
+
specification_version: 4
|
134
112
|
summary: Handling xml with my own ten-foot poll.
|
135
|
-
test_files:
|
113
|
+
test_files:
|
136
114
|
- spec/spec_helper.rb
|
137
115
|
- spec/xml_hate/document_spec.rb
|
138
116
|
- spec/xml_hate/node_spec.rb
|
data/.rvmrc
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
-
# development environment upon cd'ing into the directory
|
5
|
-
|
6
|
-
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
-
environment_id="ruby-1.8.7-p352@xml_hate"
|
8
|
-
|
9
|
-
#
|
10
|
-
# Uncomment following line if you want options to be set only for given project.
|
11
|
-
#
|
12
|
-
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
-
|
14
|
-
#
|
15
|
-
# First we attempt to load the desired environment directly from the environment
|
16
|
-
# file. This is very fast and efficient compared to running through the entire
|
17
|
-
# CLI and selector. If you want feedback on which environment was used then
|
18
|
-
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
-
#
|
20
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
-
then
|
23
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
-
|
25
|
-
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
-
then
|
27
|
-
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
-
fi
|
29
|
-
else
|
30
|
-
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
-
if ! rvm --create "$environment_id"
|
32
|
-
then
|
33
|
-
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
-
return 1
|
35
|
-
fi
|
36
|
-
fi
|
37
|
-
|
38
|
-
#
|
39
|
-
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
-
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
-
# necessary.
|
42
|
-
#
|
43
|
-
# filename=".gems"
|
44
|
-
# if [[ -s "$filename" ]]
|
45
|
-
# then
|
46
|
-
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
47
|
-
# fi
|
48
|
-
|
49
|
-
# If you use bundler, this might be useful to you:
|
50
|
-
# if command -v bundle && [[ -s Gemfile ]]
|
51
|
-
# then
|
52
|
-
# bundle install
|
53
|
-
# fi
|
54
|
-
|
55
|
-
|
data/Guardfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
guard 'minitest' do
|
2
|
-
watch(%r|^test/test_(.*)\.rb|)
|
3
|
-
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
4
|
-
watch(%r|^test/test_helper\.rb|) { "test" }
|
5
|
-
watch(%r|^lib/(.*)\.rb|) { |m| "test/test_#{m[1]}.rb" }
|
6
|
-
|
7
|
-
watch(%r{^spec/.+_spec\.rb$})
|
8
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
9
|
-
watch(%r{^lib/xml_hate/(.+)\.rb$}) { |m| "spec/xml_hate/#{m[1]}_spec.rb" }
|
10
|
-
watch(%r{^spec/models/.+\.rb$}) { ["spec/models", "spec/acceptance"] }
|
11
|
-
watch('spec/spec_helper.rb') { "spec" }
|
12
|
-
end
|