Module: Base
- Included in:
- GoogleCurrencyExchange
- Defined in:
- lib/base.rb
Instance Method Summary collapse
Instance Method Details
#call_google_finance(amount, from, to) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/base.rb', line 2 def call_google_finance(amount, from, to) uri = URI('https://www.google.com/finance/converter') params = { :a => amount,:from => from, :to => to } uri.query = URI.encode_www_form(params) # Google api will return an html object in response res = Net::HTTP.get_response(uri) extract_exchanged_amount(res.body) end |
#extract_exchanged_amount(data) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/base.rb', line 11 def extract_exchanged_amount(data) amount = data[/[bld]>(.*)</,1] if amount.nil? return "Check & correct currency codes" else return amount end end |