Never been to DZone Snippets before?

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

itcrowdquote.rb (See related posts)

// 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

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts