nokogiri-happymapper 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.md +5 -1
- data/README.md +74 -53
- data/lib/happymapper/anonymous_mapper.rb +114 -0
- data/lib/happymapper/attribute.rb +20 -2
- data/lib/happymapper/element.rb +52 -2
- data/lib/happymapper/item.rb +89 -182
- data/lib/happymapper/supported_types.rb +140 -0
- data/lib/happymapper/text_node.rb +6 -1
- data/lib/happymapper/version.rb +3 -0
- data/lib/happymapper.rb +42 -22
- data/spec/attribute_default_value_spec.rb +50 -0
- data/spec/fixtures/default_namespace_combi.xml +2 -1
- data/spec/happymapper/attribute_spec.rb +12 -0
- data/spec/happymapper/element_spec.rb +9 -0
- data/spec/{happymapper_item_spec.rb → happymapper/item_spec.rb} +5 -5
- data/spec/happymapper/text_node_spec.rb +9 -0
- data/spec/happymapper_parse_spec.rb +87 -0
- data/spec/happymapper_spec.rb +9 -3
- data/spec/ignay_spec.rb +22 -22
- data/spec/inheritance_spec.rb +61 -0
- data/spec/parse_with_object_to_update_spec.rb +111 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/to_xml_spec.rb +200 -0
- data/spec/to_xml_with_namespaces_spec.rb +196 -0
- data/spec/wilcard_tag_name_spec.rb +96 -0
- data/spec/wrap_spec.rb +82 -0
- data/spec/xpath_spec.rb +60 -59
- metadata +34 -33
- data/TODO +0 -0
- data/spec/happymapper_attribute_spec.rb +0 -21
- data/spec/happymapper_element_spec.rb +0 -21
- data/spec/happymapper_generic_base_spec.rb +0 -92
- data/spec/happymapper_text_node_spec.rb +0 -21
- data/spec/happymapper_to_xml_namespaces_spec.rb +0 -196
- data/spec/happymapper_to_xml_spec.rb +0 -203
- data/spec/happymapper_wrap_spec.rb +0 -69
- data/spec/parse_instance_spec.rb +0 -129
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ToXMLWithNamespaces
|
4
|
+
|
5
|
+
#
|
6
|
+
# Similar example as the to_xml but this time with namespacing
|
7
|
+
#
|
8
|
+
class Address
|
9
|
+
include HappyMapper
|
10
|
+
|
11
|
+
register_namespace 'address', 'http://www.company.com/address'
|
12
|
+
register_namespace 'country', 'http://www.company.com/country'
|
13
|
+
|
14
|
+
tag 'Address'
|
15
|
+
namespace 'address'
|
16
|
+
|
17
|
+
element :country, 'Country', :tag => 'country', :namespace => 'country'
|
18
|
+
|
19
|
+
attribute :location, String, :on_save => :when_saving_location
|
20
|
+
|
21
|
+
element :street, String
|
22
|
+
element :postcode, String
|
23
|
+
element :city, String
|
24
|
+
|
25
|
+
element :housenumber, String
|
26
|
+
|
27
|
+
#
|
28
|
+
# to_xml will default to the attr_accessor method and not the attribute,
|
29
|
+
# allowing for that to be overwritten
|
30
|
+
#
|
31
|
+
def housenumber
|
32
|
+
"[#{@housenumber}]"
|
33
|
+
end
|
34
|
+
|
35
|
+
def when_saving_location(loc)
|
36
|
+
loc + '-live'
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Write a empty element even if this is not specified
|
41
|
+
#
|
42
|
+
element :description, String, :state_when_nil => true
|
43
|
+
|
44
|
+
#
|
45
|
+
# Perform the on_save operation when saving
|
46
|
+
#
|
47
|
+
has_one :date_created, Time, :on_save => lambda {|time| DateTime.parse(time).strftime("%T %D") if time }
|
48
|
+
|
49
|
+
#
|
50
|
+
# Write multiple elements and call on_save when saving
|
51
|
+
#
|
52
|
+
has_many :dates_updated, Time, :on_save => lambda {|times|
|
53
|
+
times.compact.map {|time| DateTime.parse(time).strftime("%T %D") } if times }
|
54
|
+
|
55
|
+
#
|
56
|
+
# Class composition
|
57
|
+
#
|
58
|
+
|
59
|
+
def initialize(parameters)
|
60
|
+
parameters.each_pair do |property,value|
|
61
|
+
send("#{property}=",value) if respond_to?("#{property}=")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Country is composed above the in Address class. Here is a demonstration
|
69
|
+
# of how to_xml will handle class composition as well as utilizing the tag
|
70
|
+
# value.
|
71
|
+
#
|
72
|
+
class Country
|
73
|
+
include HappyMapper
|
74
|
+
|
75
|
+
register_namespace 'countryName', 'http://www.company.com/countryName'
|
76
|
+
|
77
|
+
attribute :code, String, :tag => 'countryCode'
|
78
|
+
has_one :name, String, :tag => 'countryName', :namespace => 'countryName'
|
79
|
+
|
80
|
+
def initialize(parameters)
|
81
|
+
parameters.each_pair do |property,value|
|
82
|
+
send("#{property}=",value) if respond_to?("#{property}=")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
#
|
90
|
+
# This class is an example of a class that has a default namespace
|
91
|
+
#xmlns="urn:eventis:prodis:onlineapi:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
92
|
+
#
|
93
|
+
class Recipe
|
94
|
+
include HappyMapper
|
95
|
+
|
96
|
+
# this is the default namespace of the document
|
97
|
+
register_namespace 'xmlns', 'urn:eventis:prodis:onlineapi:1.0'
|
98
|
+
register_namespace 'xsi', "http://www.w3.org/2001/XMLSchema-instance"
|
99
|
+
register_namespace 'xsd', "http://www.w3.org/2001/XMLSchema"
|
100
|
+
|
101
|
+
has_many :ingredients, String
|
102
|
+
|
103
|
+
def initialize(parameters)
|
104
|
+
parameters.each_pair {|property,value| send("#{property}=",value) if respond_to?("#{property}=") }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "Saving #to_xml", "with xml namespaces" do
|
110
|
+
|
111
|
+
context "#to_xml", "with namespaces" do
|
112
|
+
|
113
|
+
let(:subject) do
|
114
|
+
address = ToXMLWithNamespaces::Address.new('street' => 'Mockingbird Lane',
|
115
|
+
'location' => 'Home',
|
116
|
+
'housenumber' => '1313',
|
117
|
+
'postcode' => '98103',
|
118
|
+
'city' => 'Seattle',
|
119
|
+
'country' => ToXMLWithNamespaces::Country.new(:name => 'USA', :code => 'us'),
|
120
|
+
'date_created' => '2011-01-01 15:00:00')
|
121
|
+
|
122
|
+
|
123
|
+
address.dates_updated = ["2011-01-01 16:01:00","2011-01-02 11:30:01"]
|
124
|
+
|
125
|
+
Nokogiri::XML(address.to_xml).root
|
126
|
+
end
|
127
|
+
|
128
|
+
it "saves elements" do
|
129
|
+
elements = { 'street' => 'Mockingbird Lane', 'postcode' => '98103', 'city' => 'Seattle' }
|
130
|
+
|
131
|
+
elements.each_pair do |property,value|
|
132
|
+
expect(subject.xpath("address:#{property}").text).to eq value
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "saves attributes" do
|
137
|
+
expect(subject.xpath('@location').text).to eq "Home-live"
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when an element has a 'state_when_nil' parameter" do
|
141
|
+
it "saves an empty element" do
|
142
|
+
expect(subject.xpath('address:description').text).to eq ""
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when an element has a 'on_save' parameter" do
|
147
|
+
context "with a symbol which represents a function" do
|
148
|
+
it "saves the element with the result of a function call and not the value of the instance variable" do
|
149
|
+
expect(subject.xpath("address:housenumber").text).to eq "[1313]"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "with a lambda" do
|
154
|
+
it "saves the results" do
|
155
|
+
expect(subject.xpath('address:date_created').text).to eq "15:00:00 01/01/11"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when an attribute has a 'on_save' parameter" do
|
161
|
+
context "with a lambda" do
|
162
|
+
it "saves the result" do
|
163
|
+
expect(subject.xpath('@location').text).to eq "Home-live"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "when a has_many has a 'on_save' parameter" do
|
169
|
+
context "with a lambda" do
|
170
|
+
it "saves the result" do
|
171
|
+
dates_updated = subject.xpath('address:dates_updated')
|
172
|
+
expect(dates_updated.length).to eq 2
|
173
|
+
expect(dates_updated.first.text).to eq "16:01:00 01/01/11"
|
174
|
+
expect(dates_updated.last.text).to eq "11:30:01 01/02/11"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "when an element type is a HappyMapper subclass" do
|
180
|
+
it "saves attributes" do
|
181
|
+
expect(subject.xpath('country:country/@country:countryCode').text).to eq "us"
|
182
|
+
end
|
183
|
+
|
184
|
+
it "saves elements" do
|
185
|
+
expect(subject.xpath('country:country/countryName:countryName').text).to eq "USA"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "with a default namespace" do
|
191
|
+
it "writes the default namespace to xml without repeating xmlns" do
|
192
|
+
recipe = ToXMLWithNamespaces::Recipe.new(:ingredients => ['One Cup Flour', 'Two Scoops of Lovin'])
|
193
|
+
expect(recipe.to_xml).to match /xmlns=\"urn:eventis:prodis:onlineapi:1\.0\"/
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Wildcard Root Tag" do
|
4
|
+
|
5
|
+
generic_class_xml = %{
|
6
|
+
<root>
|
7
|
+
<description>some description</description>
|
8
|
+
<blarg name='blargname1' href='http://blarg.com'/>
|
9
|
+
<blarg name='blargname2' href='http://blarg.com'/>
|
10
|
+
<jello name='jelloname' href='http://jello.com'/>
|
11
|
+
<subelement>
|
12
|
+
<jello name='subjelloname' href='http://ohnojello.com' other='othertext'/>
|
13
|
+
</subelement>
|
14
|
+
</root>}
|
15
|
+
|
16
|
+
module GenericBase
|
17
|
+
class Base
|
18
|
+
include Comparable
|
19
|
+
include HappyMapper
|
20
|
+
|
21
|
+
def initialize(params = {})
|
22
|
+
@name = params[:name]
|
23
|
+
@href = params[:href]
|
24
|
+
@other = params[:other]
|
25
|
+
end
|
26
|
+
|
27
|
+
tag '*'
|
28
|
+
attribute :name, String
|
29
|
+
attribute :href, String
|
30
|
+
attribute :other, String
|
31
|
+
|
32
|
+
def <=>(compared)
|
33
|
+
name <=> compared.name && href <=> compared.href && other <=> compared.other
|
34
|
+
end
|
35
|
+
end
|
36
|
+
class Sub
|
37
|
+
include HappyMapper
|
38
|
+
tag 'subelement'
|
39
|
+
has_one :jello, Base, :tag => 'jello'
|
40
|
+
end
|
41
|
+
class Root
|
42
|
+
include HappyMapper
|
43
|
+
tag 'root'
|
44
|
+
element :description, String
|
45
|
+
has_many :blargs, Base, :tag => 'blarg', :xpath => '.'
|
46
|
+
has_many :jellos, Base, :tag => 'jello', :xpath => '.'
|
47
|
+
has_many :subjellos, Base, :tag => 'jello', :xpath => 'subelement/.', :read_only => true
|
48
|
+
has_one :sub_element, Sub
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "can have generic classes using tag '*'" do
|
53
|
+
|
54
|
+
let(:subject) { GenericBase::Root.parse(generic_class_xml) }
|
55
|
+
let(:xml) { Nokogiri::XML(subject.to_xml) }
|
56
|
+
|
57
|
+
it 'should map different elements to same class' do
|
58
|
+
subject.blargs.should_not be_nil
|
59
|
+
subject.jellos.should_not be_nil
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should filter on xpath appropriately' do
|
63
|
+
subject.blargs.should have(2).items
|
64
|
+
subject.jellos.should have(1).items
|
65
|
+
subject.subjellos.should have(1).items
|
66
|
+
end
|
67
|
+
|
68
|
+
def base_with(name,href,other)
|
69
|
+
GenericBase::Base.new(:name => name,:href => href,:other => other)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should parse correct values onto generic class' do
|
73
|
+
expect(subject.blargs[0]).to eq base_with('blargname1','http://blarg.com',nil)
|
74
|
+
expect(subject.blargs[1]).to eq base_with('blargname2','http://blarg.com',nil)
|
75
|
+
expect(subject.jellos[0]).to eq base_with('jelloname','http://jello.com',nil)
|
76
|
+
expect(subject.subjellos[0]).to eq base_with('subjelloname','http://ohnojello.com','othertext')
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate_xpath(xpath,name,href,other)
|
80
|
+
expect(xml.xpath("#{xpath}/@name").text).to eq name
|
81
|
+
expect(xml.xpath("#{xpath}/@href").text).to eq href
|
82
|
+
expect(xml.xpath("#{xpath}/@other").text).to eq other
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should #to_xml using parent element tag name' do
|
86
|
+
xml.xpath('/root/description').text.should == 'some description'
|
87
|
+
validate_xpath("/root/blarg[1]","blargname1","http://blarg.com","")
|
88
|
+
validate_xpath("/root/blarg[2]","blargname2","http://blarg.com","")
|
89
|
+
validate_xpath("/root/jello[1]","jelloname","http://jello.com","")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should properly respect child HappyMapper tags if tag isn't provided on the element defintion" do
|
93
|
+
xml.xpath('root/subelement').should have(1).item
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/wrap_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "wrap which allows you to specify a wrapper element" do
|
4
|
+
|
5
|
+
module Wrap
|
6
|
+
class SubClass
|
7
|
+
include HappyMapper
|
8
|
+
tag 'subclass'
|
9
|
+
attribute :myattr, String
|
10
|
+
has_many :items, String, :tag => 'item'
|
11
|
+
end
|
12
|
+
class Root
|
13
|
+
include HappyMapper
|
14
|
+
tag 'root'
|
15
|
+
attribute :attr1, String
|
16
|
+
element :name, String
|
17
|
+
wrap 'mywraptag' do
|
18
|
+
element :description, String
|
19
|
+
has_one :subclass, SubClass
|
20
|
+
end
|
21
|
+
element :number, Integer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".parse" do
|
26
|
+
context "when given valid XML" do
|
27
|
+
let(:subject) { Wrap::Root.parse fixture_file('wrapper.xml') }
|
28
|
+
|
29
|
+
it 'sets the values correctly' do
|
30
|
+
expect(subject.attr1).to eq 'somevalue'
|
31
|
+
expect(subject.name).to eq 'myname'
|
32
|
+
expect(subject.description).to eq 'some description'
|
33
|
+
expect(subject.subclass.myattr).to eq 'attrvalue'
|
34
|
+
expect(subject.subclass.items).to have(2).items
|
35
|
+
expect(subject.subclass.items[0]).to eq 'item1'
|
36
|
+
expect(subject.subclass.items[1]).to eq 'item2'
|
37
|
+
expect(subject.number).to eq 12345
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when initialized without XML" do
|
42
|
+
let(:subject) { Wrap::Root.new }
|
43
|
+
|
44
|
+
it "anonymous classes are created so nil class values does not occur" do
|
45
|
+
expect { subject.description = 'anything' }.to_not raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".to_xml" do
|
51
|
+
let(:subject) do
|
52
|
+
root = Wrap::Root.new
|
53
|
+
root.attr1 = 'somevalue'
|
54
|
+
root.name = 'myname'
|
55
|
+
root.description = 'some description'
|
56
|
+
root.number = 12345
|
57
|
+
|
58
|
+
subclass = Wrap::SubClass.new
|
59
|
+
subclass.myattr = 'attrvalue'
|
60
|
+
subclass.items = []
|
61
|
+
subclass.items << 'item1'
|
62
|
+
subclass.items << 'item2'
|
63
|
+
|
64
|
+
root.subclass = subclass
|
65
|
+
|
66
|
+
root
|
67
|
+
end
|
68
|
+
|
69
|
+
it "generates the correct xml" do
|
70
|
+
xml = Nokogiri::XML(subject.to_xml)
|
71
|
+
expect(xml.xpath('/root/@attr1').text).to eq 'somevalue'
|
72
|
+
expect(xml.xpath('/root/name').text).to eq 'myname'
|
73
|
+
expect(xml.xpath('/root/mywraptag/description').text).to eq 'some description'
|
74
|
+
expect(xml.xpath('/root/mywraptag/subclass/@myattr').text).to eq 'attrvalue'
|
75
|
+
expect(xml.xpath('/root/mywraptag/subclass/item')).to have(2).items
|
76
|
+
expect(xml.xpath('/root/mywraptag/subclass/item[1]').text).to eq 'item1'
|
77
|
+
expect(xml.xpath('/root/mywraptag/subclass/item[2]').text).to eq 'item2'
|
78
|
+
expect(xml.xpath('/root/number').text).to eq '12345'
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/spec/xpath_spec.rb
CHANGED
@@ -1,88 +1,89 @@
|
|
1
|
-
require
|
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'
|
1
|
+
require 'spec_helper'
|
36
2
|
|
37
|
-
|
3
|
+
describe "Specifying elements and attributes with an xpath" do
|
38
4
|
|
39
|
-
class
|
40
|
-
|
5
|
+
class Item
|
6
|
+
include HappyMapper
|
41
7
|
|
42
|
-
|
43
|
-
|
8
|
+
tag 'item'
|
9
|
+
namespace 'amazing'
|
44
10
|
|
45
|
-
|
11
|
+
element :title, String
|
12
|
+
attribute :link, String, :xpath => 'amazing:link/@href'
|
13
|
+
has_one :different_link, String, :xpath => 'different:link/@href'
|
14
|
+
element :detail, String, :xpath => 'amazing:subitem/amazing:detail'
|
15
|
+
has_many :more_details_text, String, :xpath => 'amazing:subitem/amazing:more'
|
16
|
+
has_many :more_details, String, :xpath => 'amazing:subitem/amazing:more/@first|amazing:subitem/amazing:more/@alternative'
|
17
|
+
has_many :more_details_alternative, String, :xpath => 'amazing:subitem/amazing:more/@*'
|
18
|
+
|
19
|
+
has_one :baby, 'Baby', :name => 'baby', :namespace => 'amazing'
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class Baby
|
24
|
+
include HappyMapper
|
25
|
+
|
26
|
+
has_one :name, String
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:subject) { Item.parse(xml_string,:single => true) }
|
30
|
+
|
31
|
+
let(:xml_string) do
|
32
|
+
%{
|
33
|
+
<rss>
|
34
|
+
<amazing:item xmlns:amazing="http://www.amazing.com/amazing" xmlns:different="http://www.different.com/different">
|
35
|
+
<amazing:title>Test XML</amazing:title>
|
36
|
+
<different:link href="different_link" />
|
37
|
+
<amazing:link href="link_to_resources" />
|
38
|
+
<amazing:subitem>
|
39
|
+
<amazing:detail>I want to parse this</amazing:detail>
|
40
|
+
<amazing:more first="this one">more 1</amazing:more>
|
41
|
+
<amazing:more alternative="another one">more 2</amazing:more>
|
42
|
+
</amazing:subitem>
|
43
|
+
<amazing:baby>
|
44
|
+
<amazing:name>Jumbo</amazing:name>
|
45
|
+
</amazing:baby>
|
46
|
+
</amazing:item>
|
47
|
+
</rss>
|
48
|
+
}
|
49
|
+
end
|
46
50
|
|
47
51
|
it "should have a title" do
|
48
|
-
|
52
|
+
expect(subject.title).to eq "Test XML"
|
49
53
|
end
|
50
54
|
|
51
55
|
it "should find the link href value" do
|
52
|
-
|
56
|
+
expect(subject.link).to eq 'link_to_resources'
|
53
57
|
end
|
54
58
|
|
55
59
|
it "should find the link href value" do
|
56
|
-
|
60
|
+
expect(subject.different_link).to eq 'different_link'
|
57
61
|
end
|
58
62
|
|
59
63
|
it "should find this subitem based on the xpath" do
|
60
|
-
|
64
|
+
expect(subject.detail).to eq 'I want to parse this'
|
61
65
|
end
|
62
66
|
|
63
67
|
it "should find the subitems based on the xpath" do
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
expect(subject.more_details_text).to have(2).items
|
69
|
+
expect(subject.more_details_text.first).to eq "more 1"
|
70
|
+
expect(subject.more_details_text.last).to eq "more 2"
|
67
71
|
end
|
68
72
|
|
69
73
|
it "should find the subitems based on the xpath" do
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
expect(subject.more_details).to have(2).items
|
75
|
+
expect(subject.more_details.first).to eq "this one"
|
76
|
+
expect(subject.more_details.last).to eq "another one"
|
73
77
|
end
|
74
78
|
|
75
79
|
it "should find the subitems based on the xpath" do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
it "should have a baby name" do
|
81
|
-
@item.baby.name.should == "Jumbo"
|
80
|
+
expect(subject.more_details_alternative).to have(2).items
|
81
|
+
expect(subject.more_details_alternative.first).to eq "this one"
|
82
|
+
expect(subject.more_details_alternative.last).to eq "another one"
|
82
83
|
end
|
83
84
|
|
84
|
-
|
85
|
-
|
85
|
+
it "should have a baby name" do
|
86
|
+
expect(subject.baby.name).to eq "Jumbo"
|
86
87
|
end
|
87
88
|
|
88
89
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri-happymapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Damien Le Berrigaud
|
@@ -19,7 +18,6 @@ dependencies:
|
|
19
18
|
- !ruby/object:Gem::Dependency
|
20
19
|
name: nokogiri
|
21
20
|
requirement: !ruby/object:Gem::Requirement
|
22
|
-
none: false
|
23
21
|
requirements:
|
24
22
|
- - ~>
|
25
23
|
- !ruby/object:Gem::Version
|
@@ -27,7 +25,6 @@ dependencies:
|
|
27
25
|
type: :runtime
|
28
26
|
prerelease: false
|
29
27
|
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
28
|
requirements:
|
32
29
|
- - ~>
|
33
30
|
- !ruby/object:Gem::Version
|
@@ -35,7 +32,6 @@ dependencies:
|
|
35
32
|
- !ruby/object:Gem::Dependency
|
36
33
|
name: rspec
|
37
34
|
requirement: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
35
|
requirements:
|
40
36
|
- - ~>
|
41
37
|
- !ruby/object:Gem::Version
|
@@ -43,29 +39,30 @@ dependencies:
|
|
43
39
|
type: :development
|
44
40
|
prerelease: false
|
45
41
|
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
none: false
|
47
42
|
requirements:
|
48
43
|
- - ~>
|
49
44
|
- !ruby/object:Gem::Version
|
50
45
|
version: '2.8'
|
51
46
|
description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
|
52
47
|
Happymapper)
|
53
|
-
email:
|
48
|
+
email: franklin.webber@gmail.com
|
54
49
|
executables: []
|
55
50
|
extensions: []
|
56
51
|
extra_rdoc_files:
|
57
52
|
- README.md
|
58
53
|
- CHANGELOG.md
|
59
|
-
- TODO
|
60
54
|
files:
|
61
55
|
- lib/happymapper.rb
|
56
|
+
- lib/happymapper/anonymous_mapper.rb
|
62
57
|
- lib/happymapper/attribute.rb
|
63
58
|
- lib/happymapper/element.rb
|
64
59
|
- lib/happymapper/item.rb
|
60
|
+
- lib/happymapper/supported_types.rb
|
65
61
|
- lib/happymapper/text_node.rb
|
62
|
+
- lib/happymapper/version.rb
|
66
63
|
- README.md
|
67
64
|
- CHANGELOG.md
|
68
|
-
-
|
65
|
+
- spec/attribute_default_value_spec.rb
|
69
66
|
- spec/fixtures/address.xml
|
70
67
|
- spec/fixtures/ambigous_items.xml
|
71
68
|
- spec/fixtures/analytics.xml
|
@@ -92,45 +89,47 @@ files:
|
|
92
89
|
- spec/fixtures/statuses.xml
|
93
90
|
- spec/fixtures/subclass_namespace.xml
|
94
91
|
- spec/fixtures/wrapper.xml
|
95
|
-
- spec/
|
96
|
-
- spec/
|
97
|
-
- spec/
|
98
|
-
- spec/
|
92
|
+
- spec/happymapper/attribute_spec.rb
|
93
|
+
- spec/happymapper/element_spec.rb
|
94
|
+
- spec/happymapper/item_spec.rb
|
95
|
+
- spec/happymapper/text_node_spec.rb
|
96
|
+
- spec/happymapper_parse_spec.rb
|
99
97
|
- spec/happymapper_spec.rb
|
100
|
-
- spec/happymapper_text_node_spec.rb
|
101
|
-
- spec/happymapper_to_xml_namespaces_spec.rb
|
102
|
-
- spec/happymapper_to_xml_spec.rb
|
103
|
-
- spec/happymapper_wrap_spec.rb
|
104
98
|
- spec/ignay_spec.rb
|
105
|
-
- spec/
|
99
|
+
- spec/inheritance_spec.rb
|
100
|
+
- spec/parse_with_object_to_update_spec.rb
|
106
101
|
- spec/spec_helper.rb
|
102
|
+
- spec/to_xml_spec.rb
|
103
|
+
- spec/to_xml_with_namespaces_spec.rb
|
104
|
+
- spec/wilcard_tag_name_spec.rb
|
105
|
+
- spec/wrap_spec.rb
|
107
106
|
- spec/xpath_spec.rb
|
108
107
|
homepage: http://github.com/dam5s/happymapper
|
109
|
-
licenses:
|
110
|
-
|
111
|
-
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
112
|
rdoc_options: []
|
113
113
|
require_paths:
|
114
114
|
- lib
|
115
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
116
|
requirements:
|
118
117
|
- - ! '>='
|
119
118
|
- !ruby/object:Gem::Version
|
120
119
|
version: '0'
|
121
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
121
|
requirements:
|
124
122
|
- - ! '>='
|
125
123
|
- !ruby/object:Gem::Version
|
126
124
|
version: '0'
|
127
125
|
requirements: []
|
128
126
|
rubyforge_project:
|
129
|
-
rubygems_version:
|
127
|
+
rubygems_version: 2.0.3
|
130
128
|
signing_key:
|
131
129
|
specification_version: 3
|
132
130
|
summary: Provides a simple way to map XML to Ruby Objects and back again.
|
133
131
|
test_files:
|
132
|
+
- spec/attribute_default_value_spec.rb
|
134
133
|
- spec/fixtures/address.xml
|
135
134
|
- spec/fixtures/ambigous_items.xml
|
136
135
|
- spec/fixtures/analytics.xml
|
@@ -157,16 +156,18 @@ test_files:
|
|
157
156
|
- spec/fixtures/statuses.xml
|
158
157
|
- spec/fixtures/subclass_namespace.xml
|
159
158
|
- spec/fixtures/wrapper.xml
|
160
|
-
- spec/
|
161
|
-
- spec/
|
162
|
-
- spec/
|
163
|
-
- spec/
|
159
|
+
- spec/happymapper/attribute_spec.rb
|
160
|
+
- spec/happymapper/element_spec.rb
|
161
|
+
- spec/happymapper/item_spec.rb
|
162
|
+
- spec/happymapper/text_node_spec.rb
|
163
|
+
- spec/happymapper_parse_spec.rb
|
164
164
|
- spec/happymapper_spec.rb
|
165
|
-
- spec/happymapper_text_node_spec.rb
|
166
|
-
- spec/happymapper_to_xml_namespaces_spec.rb
|
167
|
-
- spec/happymapper_to_xml_spec.rb
|
168
|
-
- spec/happymapper_wrap_spec.rb
|
169
165
|
- spec/ignay_spec.rb
|
170
|
-
- spec/
|
166
|
+
- spec/inheritance_spec.rb
|
167
|
+
- spec/parse_with_object_to_update_spec.rb
|
171
168
|
- spec/spec_helper.rb
|
169
|
+
- spec/to_xml_spec.rb
|
170
|
+
- spec/to_xml_with_namespaces_spec.rb
|
171
|
+
- spec/wilcard_tag_name_spec.rb
|
172
|
+
- spec/wrap_spec.rb
|
172
173
|
- spec/xpath_spec.rb
|
data/TODO
DELETED
File without changes
|