All pastes #46659 Raw Edit

Untitled

public ruby v1 · immutable
#46659 ·published 2006-03-22 23:03 UTC
rendered paste body
#!/bin/env ruby# $Id$require 'game'require 'language_extensions'require 'rexml/document'include REXMLclass XBoxService  attr_accessor :url    def initialize(url = 'http://xbox.foo.net/xmlservice.php')    if url.nil?      raise ArgumentError, "Please specify a non-nil URL endpoint in the constructor."    else       @url = url    end  end    def get_games    parse_xml @url.fetch_as_url  end    def add_vote(game)    unless game.respond_to?(:to_vote_xml)      raise ArgumentError, "Object must respond to :to_vote_xml"    else       raise NotImplementedError    end  end    private    def parse_xml(xml)    games = []        doc = Document.new(xml)        doc.elements.each("xboxgames/games/game") do |e|      title   = e.elements['title'].text      status  = e.elements['status'].text      votes   = e.elements['votes'].text      id      = e.elements['id'].text            games << Game.new(title, status, votes, id)    end        games  end  end