class GoogleFinanceCurrencyConverter
Public Class Methods
new(params={})
click to toggle source
# File lib/google_finance_currency_converter.rb, line 4 def initialize(params={}) @from = params[:from] @to = params[:to] @amount = params[:amount] @amount = 1 if @amount == nil raise "Same code" if @from == @to end
Public Instance Methods
result()
click to toggle source
# File lib/google_finance_currency_converter.rb, line 12 def result return 0 if @amount == 0 parse_response(request) end
Private Instance Methods
parse_response(response)
click to toggle source
# File lib/google_finance_currency_converter.rb, line 22 def parse_response(response) scanned_result = response.scan(/<span class=bld>([^.]+(?:\.(?:\d+))?)/) raise "Result not found" if scanned_result.empty? scanned_result[0][0].to_f end
request()
click to toggle source
# File lib/google_finance_currency_converter.rb, line 18 def request open("http://www.google.com/finance/converter?a=#{@amount}&from=#{@from}&to=#{@to}").read end