jnunemaker-happymapper 0.1.5 → 0.1.6

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/happymapper.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{happymapper}
5
- s.version = "0.1.5"
5
+ s.version = "0.1.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Nunemaker"]
data/lib/happymapper.rb CHANGED
@@ -75,7 +75,17 @@ module HappyMapper
75
75
  else
76
76
  doc.find("//#{get_tag_name}")
77
77
  end
78
-
78
+
79
+ nodes = if namespace
80
+ node = doc.respond_to?(:root) ? doc.root : doc
81
+ node.register_default_namespace(namespace.chop)
82
+ node.find("#{namespace}#{get_tag_name}")
83
+ else
84
+ nested = '.' unless doc.respond_to?(:root)
85
+ path = "#{nested}//#{get_tag_name}"
86
+ doc.find(path)
87
+ end
88
+
79
89
  collection = create_collection(nodes, namespace)
80
90
 
81
91
  # per http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Document.html#M000354
@@ -1,5 +1,16 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
+ class Place
4
+ include HappyMapper
5
+
6
+ element :name, String
7
+ end
8
+
9
+ class Radar
10
+ include HappyMapper
11
+ has_many :places, Place
12
+ end
13
+
3
14
  class Post
4
15
  include HappyMapper
5
16
 
@@ -261,4 +272,23 @@ describe HappyMapper do
261
272
  @first.current_condition.icon.should == 'http://deskwx.weatherbug.com/images/Forecast/icons/cond007.gif'
262
273
  end
263
274
  end
275
+
276
+ describe "#parse (with xml that has nested elements)" do
277
+ before do
278
+ file_contents = File.read(File.dirname(__FILE__) + '/fixtures/radar.xml')
279
+ @radars = Radar.parse(file_contents)
280
+ end
281
+
282
+ it "should properly create objects" do
283
+ @first = @radars[0]
284
+ @first.places.size.should == 1
285
+ @first.places[0].name.should == 'Store'
286
+ @second = @radars[1]
287
+ @second.places.size.should == 0
288
+ @third = @radars[2]
289
+ @third.places.size.should == 2
290
+ @third.places[0].name.should == 'Work'
291
+ @third.places[1].name.should == 'Home'
292
+ end
293
+ end
264
294
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker