def exchange_rate
      url = "/currencyconverter/convert/?Amount=1&From=#{from_currency.to_s.upcase}&To=#{to_currency.to_s.upcase}"
      uri = URI.parse('https://www.xe.com')

      request = Net::HTTP.new(uri.host, uri.port)
      request.use_ssl = true
      response = request.get(url)

      doc = Nokogiri::HTML(response.body)
      result = doc.css('span.uccResultAmount').text

      regexp = Regexp.new('(\\d+(?:\\.\\d+)?)')
      regexp.match result

      return $1
    rescue Timeout::Error
      raise StandardError, 'Please check your internet connection'
    end
def exchange_rate
      url = "/currencyconverter/convert/?Amount=1&From=#{from_currency.to_s.upcase}&To=#{to_currency.to_s.upcase}"
      uri = URI.parse('https://www.xe.com')

      request = Net::HTTP.new(uri.host, uri.port)
      request.use_ssl = true
      response = request.get(url)

      doc = Nokogiri::HTML(response.body)
      result = doc.css('span.uccResultAmount').text

      regexp = Regexp.new('(\\d+(?:\\.\\d+)?)')
      regexp.match result

      return $1
    rescue Timeout::Error
      raise StandardError, 'Please check your internet connection'
    end
def exchange_rate url = "/currencyconverter/convert/?Amount=1&From=#{from_currency.to_s.upcase}&To=#{to_currency.to_s.upcase}" uri = URI . parse ( 'https://www.xe.com' ) request = Net :: HTTP . new ( uri . host , uri . port ) request . use_ssl = true response = request . get ( url ) doc = Nokogiri :: HTML ( response . body ) result = doc . css ( 'span.uccResultAmount' ) . text regexp = Regexp . new ( '(\\d+(?:\\.\\d+)?)' ) regexp . match result return $1 rescue Timeout :: Error raise StandardError , 'Please check your internet connection' end
Returns the Float value of rate or nil
Returns the Float value of rate or nil