julien51-sax-machine 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
data/lib/sax-machine.rb
CHANGED
@@ -45,7 +45,7 @@ module SAXMachine
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def end_element(name)
|
48
|
-
if parsing_collection? && @collection_config.name == name
|
48
|
+
if parsing_collection? && @collection_config.name == name.split(':').last
|
49
49
|
@collection_handler.end_element(name)
|
50
50
|
@object.send(@collection_config.accessor) << @collection_handler.object
|
51
51
|
reset_current_collection
|
@@ -542,37 +542,71 @@ eoxml
|
|
542
542
|
@document.link.should == 'http://feeds.delicious.com/v2/rss/tag/pubsubhubbub?count=15'
|
543
543
|
end
|
544
544
|
end
|
545
|
+
end
|
546
|
+
|
547
|
+
describe "yet another full example" do
|
548
|
+
|
545
549
|
context "when parsing a Twitter example" do
|
546
550
|
before :all do
|
547
|
-
|
551
|
+
|
552
|
+
RSS_XMLNS = ['http://purl.org/rss/1.0/', '']
|
553
|
+
|
554
|
+
ATOM_XMLNS = 'http://www.w3.org/2005/Atom' unless defined? ATOM_XMLNS
|
555
|
+
class Link
|
556
|
+
include SAXMachine
|
557
|
+
end
|
558
|
+
|
559
|
+
class Entry
|
560
|
+
include SAXMachine
|
561
|
+
element :title, :xmlns => RSS_XMLNS
|
562
|
+
element :link, :xmlns => RSS_XMLNS, :as => :entry_link
|
563
|
+
element :title, :xmlns => ATOM_XMLNS, :as => :title
|
564
|
+
elements :link, :xmlns => ATOM_XMLNS, :as => :links, :class => Link
|
565
|
+
end
|
566
|
+
|
567
|
+
class Feed
|
568
|
+
include SAXMachine
|
569
|
+
element :title, :xmlns => RSS_XMLNS, :as => :title
|
570
|
+
element :link, :xmlns => RSS_XMLNS, :as => :feed_link
|
571
|
+
elements :item, :xmlns => RSS_XMLNS, :as => :entries, :class => Entry
|
572
|
+
element :title, :xmlns => ATOM_XMLNS, :as => :title
|
573
|
+
elements :link, :xmlns => ATOM_XMLNS, :as => :links, :class => Link
|
574
|
+
end
|
575
|
+
|
576
|
+
@document = Feed.parse(<<-eoxml)
|
548
577
|
<?xml version="1.0" encoding="UTF-8"?>
|
549
|
-
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
</
|
578
|
+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
579
|
+
<channel>
|
580
|
+
<atom:link type="application/rss+xml" rel="self" href="http://twitter.com/statuses/user_timeline/5381582.rss"/>
|
581
|
+
<title>Twitter / julien51</title>
|
582
|
+
<link>http://twitter.com/julien51</link>
|
583
|
+
<description>Twitter updates from julien / julien51.</description>
|
584
|
+
<language>en-us</language>
|
585
|
+
<ttl>40</ttl>
|
586
|
+
<item>
|
587
|
+
<title>julien51: @github : I get an error when trying to build one of my gems (julien51-sax-machine), it seems related to another gem's gemspec.</title>
|
588
|
+
<description>julien51: @github : I get an error when trying to build one of my gems (julien51-sax-machine), it seems related to another gem's gemspec.</description>
|
589
|
+
<pubDate>Thu, 30 Jul 2009 01:00:30 +0000</pubDate>
|
590
|
+
<guid>http://twitter.com/julien51/statuses/2920716033</guid>
|
591
|
+
<link>http://twitter.com/julien51/statuses/2920716033</link>
|
592
|
+
</item>
|
593
|
+
<item>
|
594
|
+
<title>julien51: Hum, San Francisco's summer are delightful. http://bit.ly/VeXt4</title>
|
595
|
+
<description>julien51: Hum, San Francisco's summer are delightful. http://bit.ly/VeXt4</description>
|
596
|
+
<pubDate>Wed, 29 Jul 2009 23:07:32 +0000</pubDate>
|
597
|
+
<guid>http://twitter.com/julien51/statuses/2918869948</guid>
|
598
|
+
<link>http://twitter.com/julien51/statuses/2918869948</link>
|
599
|
+
</item>
|
600
|
+
</channel>
|
601
|
+
</rss>
|
566
602
|
eoxml
|
567
603
|
end
|
568
604
|
it "should parse the title" do
|
569
605
|
@document.title.should == 'Twitter / julien51'
|
570
606
|
end
|
571
|
-
|
572
|
-
@document.link.should == 'http://twitter.com/statuses/user_timeline/5381582.rss'
|
573
|
-
end
|
607
|
+
|
574
608
|
it "should find an entry" do
|
575
|
-
@document.entries.length.should ==
|
609
|
+
@document.entries.length.should == 2
|
576
610
|
end
|
577
611
|
end
|
578
612
|
end
|