nokogiri-happymapper 0.3.6 → 0.5.1
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.
- data/README.md +521 -0
- data/lib/happymapper.rb +493 -43
- data/lib/happymapper/item.rb +61 -8
- data/spec/fixtures/ambigous_items.xml +1 -1
- data/spec/fixtures/atom.xml +19 -0
- data/spec/fixtures/inagy.xml +85 -0
- data/spec/fixtures/optional_attributes.xml +6 -0
- data/spec/fixtures/subclass_namespace.xml +50 -0
- data/spec/happymapper_spec.rb +220 -6
- data/spec/happymapper_to_xml_namespaces_spec.rb +196 -0
- data/spec/happymapper_to_xml_spec.rb +196 -0
- data/spec/ignay_spec.rb +95 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/xpath_spec.rb +88 -0
- metadata +70 -68
- data/README +0 -62
- data/spec/spec.opts +0 -1
data/spec/spec_helper.rb
CHANGED
data/spec/xpath_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
test_xml = %{
|
4
|
+
<rss>
|
5
|
+
<amazing:item xmlns:amazing="http://www.amazing.com/amazing" xmlns:different="http://www.different.com/different">
|
6
|
+
<amazing:title>Test XML</amazing:title>
|
7
|
+
<different:link href="different_link" />
|
8
|
+
<amazing:link href="link_to_resources" />
|
9
|
+
<amazing:subitem>
|
10
|
+
<amazing:detail>I want to parse this</amazing:detail>
|
11
|
+
<amazing:more first="this one">more 1</amazing:more>
|
12
|
+
<amazing:more alternative="another one">more 2</amazing:more>
|
13
|
+
</amazing:subitem>
|
14
|
+
<amazing:baby>
|
15
|
+
<amazing:name>Jumbo</amazing:name>
|
16
|
+
</amazing:baby>
|
17
|
+
</amazing:item>
|
18
|
+
</rss>
|
19
|
+
}
|
20
|
+
|
21
|
+
class Item
|
22
|
+
include HappyMapper
|
23
|
+
|
24
|
+
tag 'item'
|
25
|
+
namespace 'amazing'
|
26
|
+
|
27
|
+
element :title, String
|
28
|
+
attribute :link, String, :xpath => 'amazing:link/@href'
|
29
|
+
has_one :different_link, String, :xpath => 'different:link/@href'
|
30
|
+
element :detail, String, :xpath => 'amazing:subitem/amazing:detail'
|
31
|
+
has_many :more_details_text, String, :xpath => 'amazing:subitem/amazing:more'
|
32
|
+
has_many :more_details, String, :xpath => 'amazing:subitem/amazing:more/@first|amazing:subitem/amazing:more/@alternative'
|
33
|
+
has_many :more_details_alternative, String, :xpath => 'amazing:subitem/amazing:more/@*'
|
34
|
+
|
35
|
+
has_one :baby, 'Baby', :name => 'baby', :namespace => 'amazing'
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class Baby
|
40
|
+
include HappyMapper
|
41
|
+
|
42
|
+
has_one :name, String
|
43
|
+
end
|
44
|
+
|
45
|
+
describe HappyMapper do
|
46
|
+
|
47
|
+
it "should have a title" do
|
48
|
+
@item.title.should == "Test XML"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should find the link href value" do
|
52
|
+
@item.link.should == 'link_to_resources'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should find the link href value" do
|
56
|
+
@item.different_link.should == 'different_link'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should find this subitem based on the xpath" do
|
60
|
+
@item.detail.should == 'I want to parse this'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should find the subitems based on the xpath" do
|
64
|
+
@item.more_details_text.length.should == 2
|
65
|
+
@item.more_details_text.first.should == "more 1"
|
66
|
+
@item.more_details_text.last.should == "more 2"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should find the subitems based on the xpath" do
|
70
|
+
@item.more_details.length.should == 2
|
71
|
+
@item.more_details.first.should == "this one"
|
72
|
+
@item.more_details.last.should == "another one"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should find the subitems based on the xpath" do
|
76
|
+
@item.more_details.length.should == 2
|
77
|
+
@item.more_details_alternative.first.should == "this one"
|
78
|
+
@item.more_details_alternative.last.should == "another one"
|
79
|
+
end
|
80
|
+
it "should have a baby name" do
|
81
|
+
@item.baby.name.should == "Jumbo"
|
82
|
+
end
|
83
|
+
|
84
|
+
before(:all) do
|
85
|
+
@item = Item.parse(test_xml,:single => true)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
metadata
CHANGED
@@ -1,84 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri-happymapper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 6
|
9
|
-
version: 0.3.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Damien Le Berrigaud
|
13
9
|
- John Nunemaker
|
14
10
|
- David Bolton
|
15
11
|
- Roland Swingler
|
16
12
|
- Etienne Vallette d'Osia
|
13
|
+
- Franklin Webber
|
17
14
|
autorequire:
|
18
15
|
bindir: bin
|
19
16
|
cert_chain: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
dependencies:
|
24
|
-
- !ruby/object:Gem::Dependency
|
17
|
+
date: 2011-08-22 00:00:00.000000000 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
25
20
|
name: nokogiri
|
26
|
-
|
27
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
requirement: !ruby/object:Gem::Requirement
|
28
22
|
none: false
|
29
|
-
requirements:
|
23
|
+
requirements:
|
30
24
|
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
33
|
-
- 1
|
34
|
-
- 4
|
35
|
-
- 2
|
36
|
-
version: 1.4.2
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
37
27
|
type: :runtime
|
38
|
-
version_requirements: *id001
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: rspec
|
41
28
|
prerelease: false
|
42
|
-
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
30
|
none: false
|
44
|
-
requirements:
|
31
|
+
requirements:
|
45
32
|
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.4'
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.8'
|
52
43
|
type: :development
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ~>
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '2.8'
|
51
|
+
description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
|
52
|
+
Happymapper)
|
53
|
+
email: franklin.webber@gmail.com
|
56
54
|
executables: []
|
57
|
-
|
58
55
|
extensions: []
|
59
|
-
|
60
|
-
|
61
|
-
- README
|
56
|
+
extra_rdoc_files:
|
57
|
+
- README.md
|
62
58
|
- TODO
|
63
|
-
files:
|
59
|
+
files:
|
64
60
|
- lib/happymapper.rb
|
65
61
|
- lib/happymapper/attribute.rb
|
66
62
|
- lib/happymapper/element.rb
|
67
63
|
- lib/happymapper/item.rb
|
68
64
|
- lib/happymapper/text_node.rb
|
69
|
-
- README
|
65
|
+
- README.md
|
70
66
|
- TODO
|
71
67
|
- spec/fixtures/address.xml
|
72
68
|
- spec/fixtures/ambigous_items.xml
|
73
69
|
- spec/fixtures/analytics.xml
|
74
70
|
- spec/fixtures/analytics_profile.xml
|
71
|
+
- spec/fixtures/atom.xml
|
75
72
|
- spec/fixtures/commit.xml
|
76
73
|
- spec/fixtures/current_weather.xml
|
77
74
|
- spec/fixtures/dictionary.xml
|
78
75
|
- spec/fixtures/family_tree.xml
|
76
|
+
- spec/fixtures/inagy.xml
|
79
77
|
- spec/fixtures/lastfm.xml
|
80
78
|
- spec/fixtures/multiple_namespaces.xml
|
81
79
|
- spec/fixtures/multiple_primitives.xml
|
80
|
+
- spec/fixtures/optional_attributes.xml
|
82
81
|
- spec/fixtures/pita.xml
|
83
82
|
- spec/fixtures/posts.xml
|
84
83
|
- spec/fixtures/product_default_namespace.xml
|
@@ -87,57 +86,56 @@ files:
|
|
87
86
|
- spec/fixtures/quarters.xml
|
88
87
|
- spec/fixtures/radar.xml
|
89
88
|
- spec/fixtures/statuses.xml
|
89
|
+
- spec/fixtures/subclass_namespace.xml
|
90
90
|
- spec/happymapper_attribute_spec.rb
|
91
91
|
- spec/happymapper_element_spec.rb
|
92
92
|
- spec/happymapper_item_spec.rb
|
93
93
|
- spec/happymapper_spec.rb
|
94
94
|
- spec/happymapper_text_node_spec.rb
|
95
|
-
- spec/
|
95
|
+
- spec/happymapper_to_xml_namespaces_spec.rb
|
96
|
+
- spec/happymapper_to_xml_spec.rb
|
97
|
+
- spec/ignay_spec.rb
|
96
98
|
- spec/spec_helper.rb
|
97
|
-
|
98
|
-
homepage: http://github.com/
|
99
|
+
- spec/xpath_spec.rb
|
100
|
+
homepage: http://github.com/burtlo/happymapper
|
99
101
|
licenses: []
|
100
|
-
|
101
102
|
post_install_message:
|
102
103
|
rdoc_options: []
|
103
|
-
|
104
|
-
require_paths:
|
104
|
+
require_paths:
|
105
105
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
|
113
|
-
version: "0"
|
114
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
113
|
none: false
|
116
|
-
requirements:
|
117
|
-
- -
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
|
120
|
-
- 0
|
121
|
-
version: "0"
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
122
118
|
requirements: []
|
123
|
-
|
124
119
|
rubyforge_project:
|
125
|
-
rubygems_version: 1.
|
120
|
+
rubygems_version: 1.8.24
|
126
121
|
signing_key:
|
127
122
|
specification_version: 3
|
128
|
-
summary: Provides a simple way to map XML to Ruby Objects
|
129
|
-
test_files:
|
123
|
+
summary: Provides a simple way to map XML to Ruby Objects and back again.
|
124
|
+
test_files:
|
130
125
|
- spec/fixtures/address.xml
|
131
126
|
- spec/fixtures/ambigous_items.xml
|
132
127
|
- spec/fixtures/analytics.xml
|
133
128
|
- spec/fixtures/analytics_profile.xml
|
129
|
+
- spec/fixtures/atom.xml
|
134
130
|
- spec/fixtures/commit.xml
|
135
131
|
- spec/fixtures/current_weather.xml
|
136
132
|
- spec/fixtures/dictionary.xml
|
137
133
|
- spec/fixtures/family_tree.xml
|
134
|
+
- spec/fixtures/inagy.xml
|
138
135
|
- spec/fixtures/lastfm.xml
|
139
136
|
- spec/fixtures/multiple_namespaces.xml
|
140
137
|
- spec/fixtures/multiple_primitives.xml
|
138
|
+
- spec/fixtures/optional_attributes.xml
|
141
139
|
- spec/fixtures/pita.xml
|
142
140
|
- spec/fixtures/posts.xml
|
143
141
|
- spec/fixtures/product_default_namespace.xml
|
@@ -146,10 +144,14 @@ test_files:
|
|
146
144
|
- spec/fixtures/quarters.xml
|
147
145
|
- spec/fixtures/radar.xml
|
148
146
|
- spec/fixtures/statuses.xml
|
147
|
+
- spec/fixtures/subclass_namespace.xml
|
149
148
|
- spec/happymapper_attribute_spec.rb
|
150
149
|
- spec/happymapper_element_spec.rb
|
151
150
|
- spec/happymapper_item_spec.rb
|
152
151
|
- spec/happymapper_spec.rb
|
153
152
|
- spec/happymapper_text_node_spec.rb
|
154
|
-
- spec/
|
153
|
+
- spec/happymapper_to_xml_namespaces_spec.rb
|
154
|
+
- spec/happymapper_to_xml_spec.rb
|
155
|
+
- spec/ignay_spec.rb
|
155
156
|
- spec/spec_helper.rb
|
157
|
+
- spec/xpath_spec.rb
|
data/README
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
= happymapper
|
2
|
-
|
3
|
-
== DESCRIPTION:
|
4
|
-
|
5
|
-
Object to xml mapping library. I have included examples to help get you going. The specs
|
6
|
-
should also point you in the right direction.
|
7
|
-
|
8
|
-
This is a custom version of HappyMapper, available there:
|
9
|
-
http://github.com/dam5s/happymapper/
|
10
|
-
|
11
|
-
== FEATURES:
|
12
|
-
|
13
|
-
* Easy to define xml attributes and elements for an object
|
14
|
-
* Fast because it uses nokogiri under the hood
|
15
|
-
* Automatic conversion of xml to defined objects
|
16
|
-
* Reusable classes via a node finding mechanism that searches by 1. specified tag,
|
17
|
-
2. name of element, 3. class name. (gemspec was upgraded to 0.3.0 for this change)
|
18
|
-
|
19
|
-
== EXAMPLES:
|
20
|
-
|
21
|
-
Here is a simple example that maps Twitter statuses and users.
|
22
|
-
require 'happymapper'
|
23
|
-
|
24
|
-
class User
|
25
|
-
include HappyMapper
|
26
|
-
|
27
|
-
element :id, Integer
|
28
|
-
element :name, String
|
29
|
-
element :screen_name, String
|
30
|
-
element :location, String
|
31
|
-
element :description, String
|
32
|
-
element :profile_image_url, String
|
33
|
-
element :url, String
|
34
|
-
element :protected, Boolean
|
35
|
-
element :followers_count, Integer
|
36
|
-
end
|
37
|
-
|
38
|
-
class Status
|
39
|
-
include HappyMapper
|
40
|
-
|
41
|
-
element :id, Integer
|
42
|
-
element :text, String
|
43
|
-
element :created_at, Time
|
44
|
-
element :source, String
|
45
|
-
element :truncated, Boolean
|
46
|
-
element :in_reply_to_status_id, Integer
|
47
|
-
element :in_reply_to_user_id, Integer
|
48
|
-
element :favorited, Boolean
|
49
|
-
has_one :user, User
|
50
|
-
end
|
51
|
-
|
52
|
-
See examples directory in the gem for more examples.
|
53
|
-
|
54
|
-
http://github.com/dam5s/happymapper/tree/master/examples/
|
55
|
-
|
56
|
-
== INSTALL:
|
57
|
-
|
58
|
-
* sudo gem install nokogiri-happymapper
|
59
|
-
|
60
|
-
== TICKETS:
|
61
|
-
|
62
|
-
http://github.com/dam5s/happymapper/issues/
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|