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
@@ -7,5 +7,5 @@ require "sax-machine/sax_handler"
7
7
  require "sax-machine/sax_config"
8
8
 
9
9
  module SAXMachine
10
- VERSION = "0.0.19"
10
+ VERSION = "0.0.20"
11
11
  end
@@ -21,7 +21,7 @@ module SAXMachine
21
21
  end
22
22
 
23
23
  def handler(nsstack)
24
- if nsstack.nil? || nsstack[''] == ''
24
+ if @default_xmlns && (nsstack.nil? || nsstack[''] == '')
25
25
  nsstack = NSStack.new(nsstack, nsstack)
26
26
  nsstack[''] = @default_xmlns
27
27
  end
@@ -51,7 +51,7 @@ module SAXMachine
51
51
  end
52
52
 
53
53
  def column(sym)
54
- sax_config.top_level_elements[sym.to_s][0]
54
+ (sax_config.top_level_elements[sym.to_s] || []).first
55
55
  end
56
56
 
57
57
  def data_class(sym)
@@ -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
- @document = Root.parse(<<-eoxml).channels[0]
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
- <channel>
551
- <atom:link type="application/rss+xml" rel="self" href="http://twitter.com/statuses/user_timeline/5381582.rss"/>
552
- <title>Twitter / julien51</title>
553
- <link>http://twitter.com/julien51</link>
554
- <description>Twitter updates from julien / julien51.</description>
555
- <language>en-us</language>
556
- <ttl>40</ttl>
557
- <item>
558
- <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>
559
- <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>
560
- <pubDate>Thu, 30 Jul 2009 01:00:30 +0000</pubDate>
561
- <guid>http://twitter.com/julien51/statuses/2920716033</guid>
562
- <link>http://twitter.com/julien51/statuses/2920716033</link>
563
- </item>
564
- </channel>
565
- </rss>
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
- it "should parse the link" do
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 == 1
609
+ @document.entries.length.should == 2
576
610
  end
577
611
  end
578
612
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julien51-sax-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix