module CommonThread
  module RSS
    class FeedReader
      require 'open-uri'
  
      NUM_POSTS = 5
  
      def initialize(feed_url, num_posts = NUM_POSTS)
        @feed = CommonThread::XML::XmlMagic.new(open(feed_url).read)
        @num_posts = num_posts
      end
  
      def each
        entry_num = 1
    
        while entry_num <= @num_posts and entry = @feed.entry(entry_num)
          yield(FeedEntry.new(entry))
          entry_num += 1
        end
      end
    end

    class FeedEntry
      def initialize(entry)
        @entry = CommonThread::XML::XmlMagic.new(entry_doc)
      end
  
      def link
        @entry.link.href
      end
      
      def author
        @entry.author.name
      end
    end
  end
end