module Concurrency
Constants
- VERSION
Attributes
configuration[RW]
Public Class Methods
configure() { |configuration| ... }
click to toggle source
# File lib/concurrency.rb, line 19 def self.configure yield(configuration) end
conversion_rate(from = Concurrency.configuration.from_currency, to = Concurrency.configuration.to_currency)
click to toggle source
# File lib/concurrency.rb, line 33 def self.conversion_rate(from = Concurrency.configuration.from_currency, to = Concurrency.configuration.to_currency) if from == to return 1.0 else rate = Concurrency.get_rate(from, to) return rate end end
convert(*args)
click to toggle source
# File lib/concurrency.rb, line 23 def self.convert(*args) if args.length == 3 Concurrency.convert_full(*args) elsif args.length == 2 Concurrency.convert_full(args[0], Concurrency.configuration.from_currency, args[1]) else Concurrency.convert_full(args[0], Concurrency.configuration.from_currency, Concurrency.configuration.to_currency) end end
reset()
click to toggle source
# File lib/concurrency.rb, line 15 def self.reset @configuration = Configuration.new end
Private Class Methods
convert_full(initial, from, to)
click to toggle source
# File lib/concurrency.rb, line 44 def self.convert_full(initial, from, to) if from == to return initial end rate = Concurrency.get_rate(from, to) if rate == nil return nil else return initial*rate end end
get_rate(from, to)
click to toggle source
# File lib/concurrency.rb, line 56 def self.get_rate(from, to) puts "From:#{from}>>TO:#{to}>>APIKEY:#{Concurrency.configuration.api_key}" if Concurrency.configuration.api_key.nil? raise "API Key is missing. Kindly set API key CONCURRENCY_APIKEY." end url = "https://free.currencyconverterapi.com/api/v6/convert?q=#{from}_#{to}&compact=ultra&apiKey=#{Concurrency.configuration.api_key}" uri = URI(url) response = Net::HTTP.get(uri) if response == nil return nil else parsed_response = JSON.parse(response) rate = (parsed_response["#{from}_#{to}"]).to_f return rate end end