Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#!/usr/bin/env ruby %w|rubygems hpricot active_record open-uri irb|.each{|lib| require lib} class Parse attr_accessor :wines def initialize username = "*****" password = "*****" base = "http://www.cellartracker.com/xlquery.asp?table=%type%&User=#{username}&Password=#{password}" @wines = {} # full wine data ct = Hpricot::parse(open(base.gsub(/%type%/, "List"))) ct.search("//tr[@class='properties']").collect do |row| iwine = row.at("td[1]").innerHTML @wines[iwine] = { :iwine => row.at("td[1]").innerHTML, :qty => row.at("td[2]").innerHTML, :size => row.at("td[4]").innerHTML, :price => row.at("td[5]").innerHTML, :vintage => row.at("td[10]").innerHTML, :name => row.at("td[11]").innerHTML, :country => row.at("td[14]").innerHTML, :region => row.at("td[15]").innerHTML, :sub_region => row.at("td[16]").innerHTML, :appllation => row.at("td[17]").innerHTML } end # Ratings and reviews ct = Hpricot::parse(open(base.gsub(/%type%/, "Notes"))) ct.search("//tr[@class='properties']").collect do |row| iwine = row.at("td[1]").innerHTML if @wines[iwine] puts "Doing #{iwine}...#{row.at("td[9]").innerHTML}" @wines[iwine].merge!({ :rating => row.at("td[9]").innerHTML, :taste_date => row.at("td[7]").innerHTML, :notes => row.at("td[10]").innerHTML }) end end end end IRB.start if __FILE__ == $0
This paste will be private.
From the Design Piracy series on my blog: