This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

A Simple Feed Aggregator (written by Rod Gaither)
CodeExpectedActual
require 'rss/2.0'
require 'open-uri'
url = 'http://www.oreillynet.com/pub/feed/1?format=rss2'
feed = RSS::Parser.parse(open(url).read, false)
puts "=== Channel: #{feed.channel.title} ==="
feed.items.each do |item|
  puts item.title
  puts " (#{item.link})"
  puts
  puts item.description
end
=== Channel: O'Reilly Network Articles ===
How to Make Your Sound Sing with Vocoders
(http://digitalmedia.oreilly.com/2006/03/29/vocoder-tutorial-and-tips.html)
...
=== Channel: O'Reilly Network Articles ===
How to Make Your Sound Sing with Vocoders
 (http://digitalmedia.oreilly.com/2006/03/29/vocoder-tutorial-and-tips.html)

<a href='http://digitalmedia.oreilly.com/2006/03/29/vocoder-tutorial-and-tips.html'><img src='http://www.oreillynet.com/digitalmedia/2004/10/25/graphics/111-digi_audio.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>You've heard their smoothly sexy yet alien voices. Vocoders are devices that make ordinary sounds sing or speak recognizable words. In this hands-on tutorial, Jim Aikin explains how vocoders perform their magic and how to set up your own software vocoder, and shares some unexpectedly cool uses for vocoding.
Bringing Ruby on Rails with FastCGI into Mac OS X Server
 (http://www.macdevcenter.com/pub/a/mac/2006/03/29/rails.html)

<a href='http://www.macdevcenter.com/pub/a/mac/2006/03/29/rails.html'><img src='http://www.oreillynet.com/mac/2006/03/29/graphics/111-ruby_on_rails.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Most of the Ruby on Rails documentation on deployment for Mac OS X glosses over key parts of the plumbing. In this article, Luke Burton walks you through a Rails installation on Mac OS X Server.
Maven 2.0: Compile, Test, Run, Deploy, and More
 (http://www.onjava.com/pub/a/onjava/2006/03/29/maven-2-0.html)

<a href='http://www.onjava.com/pub/a/onjava/2006/03/29/maven-2-0.html'><img src='http://www.oreillynet.com/onjava/2003/10/22/graphics/111-maven.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Maven is popular for bringing order, expertise, and experience to Java project creation and management. Maven 2.0 makes a sharp break with the 1.0 line, and forges a path independent of its roots in Ant. Chris Hardin's introduction shows what Maven 2 can do for you and how to make it work.
Zero Configuration Networking: Using the Java APIs, Part 3
 (http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index2.html)

<a href='http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index2.html'><img src='http://www.oreillynet.com/onjava/2006/03/15/graphics/111-bonjour.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>In this final excerpt from <em>Zero Configuration Networking: The Definitive Guide</em>, Stuart Cheshire and Daniel H. Steinberg take the Java bindings to Apple's Zeroconf implementation and apply them to creating a networked Swing tic-tac-toe game, in which each instance can discover and compete against other instances on the network.
httplib2: HTTP Persistence and Authentication
 (http://www.xml.com/pub/a/2006/03/29/httplib2-http-persistence-and-authentication.html)

<a href='http://www.xml.com/pub/a/2006/03/29/httplib2-http-persistence-and-authentication.html'><img src='http://www.xml.com/universal/images/111-rest.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>In this latest Restful Web column, Joe Gregorio explains HTTP persistent connections, pipelining, and the sad state of HTTP authentication.
Object-Oriented Data Programming: C# Meets Cach
 (http://www.windowsdevcenter.com/pub/a/windows/2006/03/28/oop-c-meets-cache.html)

<a href='http://www.windowsdevcenter.com/pub/a/windows/2006/03/28/oop-c-meets-cache.html'><img src='http://www.oreillynet.com/windows/2006/03/28/graphics/111-csharp-cache.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>There are plenty of legacy databases using MUMPS and Cach&eacute;--but what do you do when you need to bring them into the modern world? Jesse Liberty shows you how to bridge the worlds of object-oriented data programming and old-time databases.
Obscenity, Infinity, and Bionic Beings
 (http://www.oreillynet.com/pub/a/network/2006/03/27/distributing-the-future.html)

<a href='http://www.oreillynet.com/pub/a/network/2006/03/27/distributing-the-future.html'><img src='http://www.oreillynet.com/network/2005/09/02/graphics/111-future_distro.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>This installment has more from this year's O'Reilly Emerging Technology conference. Eric Bonabeau looks at obscenity and infinity to illustrate what people and machines are particularly good at, Tim O'Reilly sets up that talk by considering the Mechanical Turk and applications of bionics, and Rael Dornfest briefly tells us to meet the people who surround us at these conferences. (DTF 03-27-2006: 29 minutes 10 seconds)
Getting Started with Quartz Composer
 (http://www.macdevcenter.com/pub/a/mac/2006/03/23/quartz-composer.html)

<a href='http://www.macdevcenter.com/pub/a/mac/2006/03/23/quartz-composer.html'><img src='http://www.oreillynet.com/mac/2003/04/25/graphics/111-gems.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Apple's free developer tool collection contains many overlooked gems. These aren't limited to programming-specific utilities. Take Quartz Composer, for example. It's a free utility that can bring new life and interest to your iMovie projects. In this article, you'll learn how to use your own pictures to create a simple but flashy animation.
Apple's High-Water Mark?
 (http://www.onlamp.com/pub/a/onlamp/2006/03/23/apple_vs_everyone.html)

<a href='http://www.onlamp.com/pub/a/onlamp/2006/03/23/apple_vs_everyone.html'><img src='http://www.oreillynet.com/onlamp/2006/03/23/graphics/111-apple_cell.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Apple's latest moves have impressed observers, but the environment is about to change drastically, with Apple likely facing its greatest challenges. Where do the company and its users face competition? IBM, Sony, and ... Linux? Adrien Lamothe explores the computing landscape of 2006.
Secure Your Linux Server
 (http://www.linuxdevcenter.com/pub/a/linux/2006/03/23/secure-your-server.html)

<a href='http://www.linuxdevcenter.com/pub/a/linux/2006/03/23/secure-your-server.html'><img src='http://www.oreillynet.com/linux/2006/03/23/graphics/111-secure_server.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Linux is a powerful and popular operating system kernel. That popularity means you might be running it even if you're not a dedicated Unix administrator or high-powered programmer. That doesn't mean that rock-solid security is out of your reach, though. Aaron Brazell shows how to make Red Hat 9 (and other Linux distributions) much more secure in a few easy steps.
Inside Animusic's Astonishing Computer Music Videos
 (http://digitalmedia.oreilly.com/2006/03/22/animusic-computer-music-videos.html)

<a href='http://digitalmedia.oreilly.com/2006/03/22/animusic-computer-music-videos.html'><img src='http://www.oreillynet.com/digitalmedia/2004/10/25/graphics/111-digi_audio.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Composer Wayne Lytle's custom software transforms musical notes into jaw-dropping 3D animations. The resulting DVDs have sold tens of thousands of copies. Watch excerpts here and learn how Lytle turned his digital pipe dream into a thriving business.
Zero Configuration Networking: Using the Java APIs, Part 2
 (http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index1.html)

<a href='http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index1.html'><img src='http://www.oreillynet.com/onjava/2006/03/15/graphics/111-bonjour.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>In this second part of an excerpt from <em>Zero Configuration Networking: The Definitive Guide</em>, Stuart Cheshire and Daniel H. Steinberg show how Java clients can browse for and resolve Zeroconf services, and how to register and add, update, and delete services with DNS TXT attributes.
Advanced Configuration of the Spring MVC Framework
 (http://www.onjava.com/pub/a/onjava/2006/03/22/advanced-spring-configuration.html)

<a href='http://www.onjava.com/pub/a/onjava/2006/03/22/advanced-spring-configuration.html'><img src='http://www.oreillynet.com/onjava/2005/05/18/graphics/111-spring.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Storing your Spring configuration files in source control makes perfect sense--until you and the rest of the development team start overwriting each other's settings, or production settings, in <em>applicationContext.xml</em>. In this article, Dejan Bosanac introduces an approach that allows for more flexible property settings and bean wirings.
RSS Feeds for FTP Servers
 (http://www.xml.com/pub/a/2006/03/22/rss-feeds-for-ftp-servers.html)

<a href='http://www.xml.com/pub/a/2006/03/22/rss-feeds-for-ftp-servers.html'><img src='http://www.xml.com/2006/03/22/graphics/111-rss_ftp.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Mark Woodman returns with another interesting RSS application: he describes a PHP library for creating RSS feeds for FTP sites. Old-school FTP meets new-school RSS!
Using the MultiView and Wizard Controls in ASP.NET 2.0
 (http://www.windowsdevcenter.com/pub/a/windows/2006/03/21/multiview-and-wizard-controls-in-aspnet-20.html)

<a href='http://www.windowsdevcenter.com/pub/a/windows/2006/03/21/multiview-and-wizard-controls-in-aspnet-20.html'><img src='http://www.oreillynet.com/windows/2006/03/21/graphics/111-multiview.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Need to collect data from Web pages? ASP.NET 2.0 makes it easy, with the use of MultiView and Wizard controls. Wei-Meng Lee shows you how to take advantage of them.
require 'rubygems'
require 'simple-rss'
url = 'http://www.oreillynet.com/pub/feed/1?format=rss2'
feed = RSS::Parser.parse(open(url).read, false)
puts "=== Channel: #{feed.channel.title} ==="
feed.items.each do |item|
  puts item.title
  puts " (#{item.link})"
  puts
  puts item.description
end
#!/usr/bin/ruby
rss-aggregator.rb - Simple RSS and Atom Feed Aggregator
Error! (Exception?) Here's stdout:
=== Channel: O'Reilly Network Articles ===
How to Make Your Sound Sing with Vocoders
 (http://digitalmedia.oreilly.com/2006/03/29/vocoder-tutorial-and-tips.html)

<a href='http://digitalmedia.oreilly.com/2006/03/29/vocoder-tutorial-and-tips.html'><img src='http://www.oreillynet.com/digitalmedia/2004/10/25/graphics/111-digi_audio.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>You've heard their smoothly sexy yet alien voices. Vocoders are devices that make ordinary sounds sing or speak recognizable words. In this hands-on tutorial, Jim Aikin explains how vocoders perform their magic and how to set up your own software vocoder, and shares some unexpectedly cool uses for vocoding.
Bringing Ruby on Rails with FastCGI into Mac OS X Server
 (http://www.macdevcenter.com/pub/a/mac/2006/03/29/rails.html)

<a href='http://www.macdevcenter.com/pub/a/mac/2006/03/29/rails.html'><img src='http://www.oreillynet.com/mac/2006/03/29/graphics/111-ruby_on_rails.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Most of the Ruby on Rails documentation on deployment for Mac OS X glosses over key parts of the plumbing. In this article, Luke Burton walks you through a Rails installation on Mac OS X Server.
Maven 2.0: Compile, Test, Run, Deploy, and More
 (http://www.onjava.com/pub/a/onjava/2006/03/29/maven-2-0.html)

<a href='http://www.onjava.com/pub/a/onjava/2006/03/29/maven-2-0.html'><img src='http://www.oreillynet.com/onjava/2003/10/22/graphics/111-maven.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Maven is popular for bringing order, expertise, and experience to Java project creation and management. Maven 2.0 makes a sharp break with the 1.0 line, and forges a path independent of its roots in Ant. Chris Hardin's introduction shows what Maven 2 can do for you and how to make it work.
Zero Configuration Networking: Using the Java APIs, Part 3
 (http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index2.html)

<a href='http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index2.html'><img src='http://www.oreillynet.com/onjava/2006/03/15/graphics/111-bonjour.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>In this final excerpt from <em>Zero Configuration Networking: The Definitive Guide</em>, Stuart Cheshire and Daniel H. Steinberg take the Java bindings to Apple's Zeroconf implementation and apply them to creating a networked Swing tic-tac-toe game, in which each instance can discover and compete against other instances on the network.
httplib2: HTTP Persistence and Authentication
 (http://www.xml.com/pub/a/2006/03/29/httplib2-http-persistence-and-authentication.html)

<a href='http://www.xml.com/pub/a/2006/03/29/httplib2-http-persistence-and-authentication.html'><img src='http://www.xml.com/universal/images/111-rest.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>In this latest Restful Web column, Joe Gregorio explains HTTP persistent connections, pipelining, and the sad state of HTTP authentication.
Object-Oriented Data Programming: C# Meets Cach
 (http://www.windowsdevcenter.com/pub/a/windows/2006/03/28/oop-c-meets-cache.html)

<a href='http://www.windowsdevcenter.com/pub/a/windows/2006/03/28/oop-c-meets-cache.html'><img src='http://www.oreillynet.com/windows/2006/03/28/graphics/111-csharp-cache.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>There are plenty of legacy databases using MUMPS and Cach&eacute;--but what do you do when you need to bring them into the modern world? Jesse Liberty shows you how to bridge the worlds of object-oriented data programming and old-time databases.
Obscenity, Infinity, and Bionic Beings
 (http://www.oreillynet.com/pub/a/network/2006/03/27/distributing-the-future.html)

<a href='http://www.oreillynet.com/pub/a/network/2006/03/27/distributing-the-future.html'><img src='http://www.oreillynet.com/network/2005/09/02/graphics/111-future_distro.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>This installment has more from this year's O'Reilly Emerging Technology conference. Eric Bonabeau looks at obscenity and infinity to illustrate what people and machines are particularly good at, Tim O'Reilly sets up that talk by considering the Mechanical Turk and applications of bionics, and Rael Dornfest briefly tells us to meet the people who surround us at these conferences. (DTF 03-27-2006: 29 minutes 10 seconds)
Getting Started with Quartz Composer
 (http://www.macdevcenter.com/pub/a/mac/2006/03/23/quartz-composer.html)

<a href='http://www.macdevcenter.com/pub/a/mac/2006/03/23/quartz-composer.html'><img src='http://www.oreillynet.com/mac/2003/04/25/graphics/111-gems.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Apple's free developer tool collection contains many overlooked gems. These aren't limited to programming-specific utilities. Take Quartz Composer, for example. It's a free utility that can bring new life and interest to your iMovie projects. In this article, you'll learn how to use your own pictures to create a simple but flashy animation.
Apple's High-Water Mark?
 (http://www.onlamp.com/pub/a/onlamp/2006/03/23/apple_vs_everyone.html)

<a href='http://www.onlamp.com/pub/a/onlamp/2006/03/23/apple_vs_everyone.html'><img src='http://www.oreillynet.com/onlamp/2006/03/23/graphics/111-apple_cell.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Apple's latest moves have impressed observers, but the environment is about to change drastically, with Apple likely facing its greatest challenges. Where do the company and its users face competition? IBM, Sony, and ... Linux? Adrien Lamothe explores the computing landscape of 2006.
Secure Your Linux Server
 (http://www.linuxdevcenter.com/pub/a/linux/2006/03/23/secure-your-server.html)

<a href='http://www.linuxdevcenter.com/pub/a/linux/2006/03/23/secure-your-server.html'><img src='http://www.oreillynet.com/linux/2006/03/23/graphics/111-secure_server.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Linux is a powerful and popular operating system kernel. That popularity means you might be running it even if you're not a dedicated Unix administrator or high-powered programmer. That doesn't mean that rock-solid security is out of your reach, though. Aaron Brazell shows how to make Red Hat 9 (and other Linux distributions) much more secure in a few easy steps.
Inside Animusic's Astonishing Computer Music Videos
 (http://digitalmedia.oreilly.com/2006/03/22/animusic-computer-music-videos.html)

<a href='http://digitalmedia.oreilly.com/2006/03/22/animusic-computer-music-videos.html'><img src='http://www.oreillynet.com/digitalmedia/2004/10/25/graphics/111-digi_audio.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Composer Wayne Lytle's custom software transforms musical notes into jaw-dropping 3D animations. The resulting DVDs have sold tens of thousands of copies. Watch excerpts here and learn how Lytle turned his digital pipe dream into a thriving business.
Zero Configuration Networking: Using the Java APIs, Part 2
 (http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index1.html)

<a href='http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index1.html'><img src='http://www.oreillynet.com/onjava/2006/03/15/graphics/111-bonjour.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>In this second part of an excerpt from <em>Zero Configuration Networking: The Definitive Guide</em>, Stuart Cheshire and Daniel H. Steinberg show how Java clients can browse for and resolve Zeroconf services, and how to register and add, update, and delete services with DNS TXT attributes.
Advanced Configuration of the Spring MVC Framework
 (http://www.onjava.com/pub/a/onjava/2006/03/22/advanced-spring-configuration.html)

<a href='http://www.onjava.com/pub/a/onjava/2006/03/22/advanced-spring-configuration.html'><img src='http://www.oreillynet.com/onjava/2005/05/18/graphics/111-spring.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Storing your Spring configuration files in source control makes perfect sense--until you and the rest of the development team start overwriting each other's settings, or production settings, in <em>applicationContext.xml</em>. In this article, Dejan Bosanac introduces an approach that allows for more flexible property settings and bean wirings.
RSS Feeds for FTP Servers
 (http://www.xml.com/pub/a/2006/03/22/rss-feeds-for-ftp-servers.html)

<a href='http://www.xml.com/pub/a/2006/03/22/rss-feeds-for-ftp-servers.html'><img src='http://www.xml.com/2006/03/22/graphics/111-rss_ftp.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Mark Woodman returns with another interesting RSS application: he describes a PHP library for creating RSS feeds for FTP sites. Old-school FTP meets new-school RSS!
Using the MultiView and Wizard Controls in ASP.NET 2.0
 (http://www.windowsdevcenter.com/pub/a/windows/2006/03/21/multiview-and-wizard-controls-in-aspnet-20.html)

<a href='http://www.windowsdevcenter.com/pub/a/windows/2006/03/21/multiview-and-wizard-controls-in-aspnet-20.html'><img src='http://www.oreillynet.com/windows/2006/03/21/graphics/111-multiview.gif' width='111px' height='91px' alt='tile image' align='left' border='0'/></a>Need to collect data from Web pages? ASP.NET 2.0 makes it easy, with the use of MultiView and Wizard controls. Wei-Meng Lee shows you how to take advantage of them.
require 'rubygems'
require 'simple-rss'
require 'open-uri'
class RSSAggregator 
  def initialize(feed_urls)
    @feed_urls = feed_urls
    @feeds = []
    read_feeds
  end
  protected
  def read_feeds
    @feed_urls.each { |url| @feeds.push(SimpleRSS.new(open(url).read)) }
  end
  public
  def refresh
    @feeds.clear
    read_feeds
  end
  def channel_counts
    @feeds.each_with_index do |feed, index|
      channel = "Channel(#{index.to_s}): #{feed.channel.title}" 
      articles = "Articles: #{feed.items.size.to_s}" 
      puts channel + ', ' + articles
    end
  end
  def list_articles(id)
    puts "=== Channel(#{id.to_s}): #{@feeds[id].channel.title} ==="
    @feeds[id].items.each { |item| puts ' ' + item.title }
  end
  def list_all
    @feeds.each_with_index { |f, i| list_articles(i) }
  end 
end
test = RSSAggregator.new(ARGV)
test.channel_counts
puts "\n"
test.list_all
[]