Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
require 'rubygems' require 'eventmachine' require 'hpricot' module ThirdParty class Collect attr_accessor :response, :status, :hpricot def initialize(server,page) @reponse = nil @status = nil @hpricot = nil @page = page @server = server get end def get EM.run do http = EM::P::HttpClient2.connect @server, 80 d = http.get @page d.callback { @response = d.content @status = d.status p @status EM.stop } end doc = Hpricot.XML(@response) @hpricot = doc end end class News attr_accessor :headlines def initialize(server, page) doc = Collect.new(server,page).hpricot @headlines = [] (doc/:entry).each {|it| @headlines << (it/:title).inner_text } end end end puts ThirdParty::News.new("news.google.com","/news?hl&output=atom").headlines
This paste will be private.
From the Design Piracy series on my blog: