nokogiri-happymapper 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +1 -0
- data/README +2 -1
- data/Rakefile +2 -2
- data/lib/happymapper.rb +23 -13
- data/lib/happymapper/version.rb +1 -1
- data/nokogiri-happymapper.gemspec +7 -7
- data/spec/fixtures/ambigous_items.xml +22 -0
- data/spec/happymapper_spec.rb +20 -4
- metadata +25 -12
data/Manifest
CHANGED
data/README
CHANGED
@@ -19,6 +19,7 @@ http://github.com/dam5s/happymapper/
|
|
19
19
|
== EXAMPLES:
|
20
20
|
|
21
21
|
Here is a simple example that maps Twitter statuses and users.
|
22
|
+
require 'happymapper'
|
22
23
|
|
23
24
|
class User
|
24
25
|
include HappyMapper
|
@@ -54,7 +55,7 @@ http://github.com/dam5s/happymapper/tree/master/examples/
|
|
54
55
|
|
55
56
|
== INSTALL:
|
56
57
|
|
57
|
-
* sudo gem install nokogiri-happymapper
|
58
|
+
* sudo gem install nokogiri-happymapper
|
58
59
|
|
59
60
|
== TICKETS:
|
60
61
|
|
data/Rakefile
CHANGED
@@ -5,10 +5,10 @@ require 'spec/rake/spectask'
|
|
5
5
|
require "lib/happymapper/version"
|
6
6
|
|
7
7
|
Echoe.new('nokogiri-happymapper', HappyMapper::Version) do |p|
|
8
|
-
p.description = "
|
8
|
+
p.description = "Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's Happymapper)"
|
9
9
|
p.install_message = "May you have many happy mappings!"
|
10
10
|
p.url = "http://github.com/dam5s/happymapper"
|
11
|
-
p.author = "Damien Le Berrigaud, John Nunemaker, David Bolton, Roland Swingler"
|
11
|
+
p.author = "Damien Le Berrigaud, John Nunemaker, David Bolton, Roland Swingler, Etienne Vallette d'Osia"
|
12
12
|
p.email = "damien@meliondesign.com"
|
13
13
|
p.extra_deps = ['nokogiri >=1.4.0']
|
14
14
|
p.need_tar_gz = false
|
data/lib/happymapper.rb
CHANGED
@@ -93,7 +93,11 @@ module HappyMapper
|
|
93
93
|
|
94
94
|
# This is the entry point into the parsing pipeline, so the default
|
95
95
|
# namespace prefix registered here will propagate down
|
96
|
-
namespaces
|
96
|
+
namespaces = options[:namespaces]
|
97
|
+
namespaces ||= {}
|
98
|
+
namespaces = namespaces.merge(xml.collect_namespaces) if xml.respond_to?(:collect_namespaces)
|
99
|
+
namespaces = namespaces.merge(xml.namespaces)
|
100
|
+
|
97
101
|
if namespaces.has_key?("xmlns")
|
98
102
|
namespace ||= DEFAULT_NS
|
99
103
|
namespaces[namespace] = namespaces.delete("xmlns")
|
@@ -101,18 +105,24 @@ module HappyMapper
|
|
101
105
|
namespace ||= DEFAULT_NS
|
102
106
|
end
|
103
107
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
108
|
+
nodes = options.fetch(:nodes) do
|
109
|
+
xpath = (root ? '/' : './/')
|
110
|
+
xpath = options[:xpath].to_s.sub(/([^\/])$/, '\1/') if options[:xpath]
|
111
|
+
xpath += "#{namespace}:" if namespace
|
112
|
+
#puts "parse: #{xpath}"
|
113
|
+
|
114
|
+
nodes = []
|
115
|
+
|
116
|
+
# when finding nodes, do it in this order:
|
117
|
+
# 1. specified tag
|
118
|
+
# 2. name of element
|
119
|
+
# 3. tag_name (derived from class name by default)
|
120
|
+
[options[:tag], options[:name], tag_name].compact.each do |xpath_ext|
|
121
|
+
nodes = node.xpath(xpath + xpath_ext.to_s, namespaces)
|
122
|
+
break if nodes && !nodes.empty?
|
123
|
+
end
|
124
|
+
|
125
|
+
nodes
|
116
126
|
end
|
117
127
|
|
118
128
|
collection = nodes.collect do |n|
|
data/lib/happymapper/version.rb
CHANGED
@@ -2,22 +2,22 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{nokogiri-happymapper}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Damien Le Berrigaud, John Nunemaker, David Bolton, Roland Swingler"]
|
9
|
-
s.date = %q{2010-
|
10
|
-
s.description = %q{
|
8
|
+
s.authors = ["Damien Le Berrigaud, John Nunemaker, David Bolton, Roland Swingler, Etienne Vallette d'Osia"]
|
9
|
+
s.date = %q{2010-06-24}
|
10
|
+
s.description = %q{Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's Happymapper)}
|
11
11
|
s.email = %q{damien@meliondesign.com}
|
12
12
|
s.extra_rdoc_files = ["README", "TODO", "lib/happymapper.rb", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/text_node.rb", "lib/happymapper/version.rb"]
|
13
|
-
s.files = ["History", "License", "Manifest", "README", "Rakefile", "TODO", "examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/family_tree.rb", "examples/post.rb", "examples/twitter.rb", "lib/happymapper.rb", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/text_node.rb", "lib/happymapper/version.rb", "nokogiri-happymapper.gemspec", "spec/fixtures/address.xml", "spec/fixtures/analytics.xml", "spec/fixtures/commit.xml", "spec/fixtures/current_weather.xml", "spec/fixtures/dictionary.xml", "spec/fixtures/family_tree.xml", "spec/fixtures/lastfm.xml", "spec/fixtures/multiple_namespaces.xml", "spec/fixtures/multiple_primitives.xml", "spec/fixtures/pita.xml", "spec/fixtures/posts.xml", "spec/fixtures/product_default_namespace.xml", "spec/fixtures/product_no_namespace.xml", "spec/fixtures/product_single_namespace.xml", "spec/fixtures/quarters.xml", "spec/fixtures/radar.xml", "spec/fixtures/statuses.xml", "spec/happymapper_attribute_spec.rb", "spec/happymapper_element_spec.rb", "spec/happymapper_item_spec.rb", "spec/happymapper_spec.rb", "spec/happymapper_text_node_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "website/css/common.css", "website/index.html"]
|
13
|
+
s.files = ["History", "License", "Manifest", "README", "Rakefile", "TODO", "examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/family_tree.rb", "examples/post.rb", "examples/twitter.rb", "lib/happymapper.rb", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/text_node.rb", "lib/happymapper/version.rb", "nokogiri-happymapper.gemspec", "spec/fixtures/address.xml", "spec/fixtures/ambigous_items.xml", "spec/fixtures/analytics.xml", "spec/fixtures/commit.xml", "spec/fixtures/current_weather.xml", "spec/fixtures/dictionary.xml", "spec/fixtures/family_tree.xml", "spec/fixtures/lastfm.xml", "spec/fixtures/multiple_namespaces.xml", "spec/fixtures/multiple_primitives.xml", "spec/fixtures/pita.xml", "spec/fixtures/posts.xml", "spec/fixtures/product_default_namespace.xml", "spec/fixtures/product_no_namespace.xml", "spec/fixtures/product_single_namespace.xml", "spec/fixtures/quarters.xml", "spec/fixtures/radar.xml", "spec/fixtures/statuses.xml", "spec/happymapper_attribute_spec.rb", "spec/happymapper_element_spec.rb", "spec/happymapper_item_spec.rb", "spec/happymapper_spec.rb", "spec/happymapper_text_node_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "website/css/common.css", "website/index.html"]
|
14
14
|
s.homepage = %q{http://github.com/dam5s/happymapper}
|
15
15
|
s.post_install_message = %q{May you have many happy mappings!}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nokogiri-happymapper", "--main", "README"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{nokogiri-happymapper}
|
19
|
-
s.rubygems_version = %q{1.3.
|
20
|
-
s.summary = %q{
|
19
|
+
s.rubygems_version = %q{1.3.6}
|
20
|
+
s.summary = %q{Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's Happymapper)}
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<ambigous>
|
3
|
+
<my-items>
|
4
|
+
<item>
|
5
|
+
<name>My first item</name>
|
6
|
+
<item><name>My first internal item</name></item>
|
7
|
+
</item>
|
8
|
+
<item>
|
9
|
+
<name>My second item</name>
|
10
|
+
<item><name>My second internal item</name></item>
|
11
|
+
</item>
|
12
|
+
<item>
|
13
|
+
<name>My third item</name>
|
14
|
+
<item><name>My third internal item</name></item>
|
15
|
+
</item>
|
16
|
+
</my-items>
|
17
|
+
<others-items>
|
18
|
+
<item>
|
19
|
+
<name>Other item</name>
|
20
|
+
</item>
|
21
|
+
<others-items>
|
22
|
+
</ambigous>
|
data/spec/happymapper_spec.rb
CHANGED
@@ -378,6 +378,16 @@ module Dictionary
|
|
378
378
|
end
|
379
379
|
end
|
380
380
|
|
381
|
+
module AmbigousItems
|
382
|
+
class Item
|
383
|
+
include HappyMapper
|
384
|
+
|
385
|
+
tag 'item'
|
386
|
+
element :name, String
|
387
|
+
element :item, String
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
381
391
|
describe HappyMapper do
|
382
392
|
|
383
393
|
describe "being included into another class" do
|
@@ -386,12 +396,12 @@ describe HappyMapper do
|
|
386
396
|
include HappyMapper
|
387
397
|
|
388
398
|
def self.to_s
|
389
|
-
'
|
399
|
+
'Boo'
|
390
400
|
end
|
391
401
|
end
|
392
402
|
end
|
393
403
|
|
394
|
-
class
|
404
|
+
class Boo; include HappyMapper end
|
395
405
|
|
396
406
|
it "should set attributes to an array" do
|
397
407
|
@klass.attributes.should == []
|
@@ -453,7 +463,7 @@ describe HappyMapper do
|
|
453
463
|
end
|
454
464
|
|
455
465
|
it "should default tag name to lowercase class" do
|
456
|
-
@klass.tag_name.should == '
|
466
|
+
@klass.tag_name.should == 'boo'
|
457
467
|
end
|
458
468
|
|
459
469
|
it "should default tag name of class in modules to the last constant lowercase" do
|
@@ -467,7 +477,7 @@ describe HappyMapper do
|
|
467
477
|
end
|
468
478
|
|
469
479
|
it "should allow setting a namespace" do
|
470
|
-
@klass.namespace(namespace = "
|
480
|
+
@klass.namespace(namespace = "boo")
|
471
481
|
@klass.namespace.should == namespace
|
472
482
|
end
|
473
483
|
|
@@ -732,4 +742,10 @@ describe HappyMapper do
|
|
732
742
|
'<em>white</em> cockatoo'
|
733
743
|
end
|
734
744
|
end
|
745
|
+
|
746
|
+
it "should parse ambigous items" do
|
747
|
+
items = AmbigousItems::Item.parse(fixture_file('ambigous_items.xml'),
|
748
|
+
:xpath => '/ambigous/my-items')
|
749
|
+
items.map(&:name).should == %w(first second third).map{|s| "My #{s} item" }
|
750
|
+
end
|
735
751
|
end
|
metadata
CHANGED
@@ -1,28 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri-happymapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 4
|
9
|
+
version: 0.3.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
|
-
- Damien Le Berrigaud, John Nunemaker, David Bolton, Roland Swingler
|
12
|
+
- Damien Le Berrigaud, John Nunemaker, David Bolton, Roland Swingler, Etienne Vallette d'Osia
|
8
13
|
autorequire:
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-06-24 00:00:00 +10:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: nokogiri
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 4
|
30
|
+
- 0
|
23
31
|
version: 1.4.0
|
24
|
-
|
25
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's Happymapper)
|
26
35
|
email: damien@meliondesign.com
|
27
36
|
executables: []
|
28
37
|
|
@@ -58,6 +67,7 @@ files:
|
|
58
67
|
- lib/happymapper/version.rb
|
59
68
|
- nokogiri-happymapper.gemspec
|
60
69
|
- spec/fixtures/address.xml
|
70
|
+
- spec/fixtures/ambigous_items.xml
|
61
71
|
- spec/fixtures/analytics.xml
|
62
72
|
- spec/fixtures/commit.xml
|
63
73
|
- spec/fixtures/current_weather.xml
|
@@ -101,20 +111,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
111
|
requirements:
|
102
112
|
- - ">="
|
103
113
|
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
104
116
|
version: "0"
|
105
|
-
version:
|
106
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
118
|
requirements:
|
108
119
|
- - ">="
|
109
120
|
- !ruby/object:Gem::Version
|
121
|
+
segments:
|
122
|
+
- 1
|
123
|
+
- 2
|
110
124
|
version: "1.2"
|
111
|
-
version:
|
112
125
|
requirements: []
|
113
126
|
|
114
127
|
rubyforge_project: nokogiri-happymapper
|
115
|
-
rubygems_version: 1.3.
|
128
|
+
rubygems_version: 1.3.6
|
116
129
|
signing_key:
|
117
130
|
specification_version: 3
|
118
|
-
summary:
|
131
|
+
summary: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's Happymapper)
|
119
132
|
test_files: []
|
120
133
|
|