# File lib/finance/currency.rb, line 40
    def Currency.convert( to, from, amount=1 )

      # Allow amount to be passed as a string.
      amount = amount.to_f if amount.kind_of?( String )

      # We always want to convert at least 1 of something.
      amount = 1 if amount == 0 || amount.nil?

      # Return immediately if there's no work to do.
      return amount.to_f if from == to

      yahoo = URI.parse( CURRENCY_URL )
      host = yahoo.host
      path = yahoo.path

      # Transparently deal with an HTTP proxy server.
      Net::HTTP::Proxy( *Finance::proxy_data ).start( host, 80 ) do |http|
        response = http.get( path + "?from=%s&to=%s&submit=Convert" %
                             [ from, to ] )
        body = response.body
        body =~ %r{
          <td\sclass="yfnc_tabledata1">
            <a\shref="/q\?s=#{from}#{to}=X">#{from}#{to}=X</a>
          </td>
          <td\sclass="yfnc_tabledata1"><b>1</b></td>
          <td\sclass="yfnc_tabledata1">[^<]+</td>
          <td\sclass="yfnc_tabledata1">(\d+\.\d+)</td>
        }x

        exchange_rate = $1.to_f          # Must be a Float for conversion to work

        if exchange_rate == 0
          raise RateError, "Exchange rate could not be determined."
        end

        exchange_rate * amount
      end
    end