DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Andrew has posted 31 posts at DZone. View Full User Profile

Itcrowdquote.rb

10.08.2007
| 3628 views |
  • submit to reddit
        // Prints a quote from Channel 4's "The IT Crowd"

#!/usr/bin/env ruby

require "rubygems"
require "open-uri"
require "hpricot"
require "htmlentities"

coder=HTMLEntities.new()

doc=open("http://www.channel4.com/entertainment/tv/microsites/I/itcrowd/quote_generator/") { |f| Hpricot(f) }

section=doc/"blockquote"/"p"
(section/"cite").remove()
quote=section.inner_html

# remove leading whitespace
quote=quote.gsub(/^\s+/, "")

# remove trailing whitespace
quote=quote.gsub(/\s+$/, $/)

# remove dash
quote=quote.gsub(/\s\-\s+$/, $/).chomp

# decode HTML entities
quote=coder.decode(quote)

puts quote