class EasyCurrency::ExchangeRate

Public Class Methods

new(currency_name) click to toggle source
# File lib/easy_currency.rb, line 8
def initialize(currency_name)
        @exchange_rates = Unirest.get("http://api.fixer.io/latest?base=#{currency_name}").body
        @base_rate = @exchange_rates["base"]
        return @base_rate
end
options() click to toggle source
# File lib/easy_currency.rb, line 37
def self.options
        options = Unirest.get("http://api.fixer.io/latest?").body["rates"]
        all_options = []
        options.each do |option, option_rate|
                all_options << option
        end
        all_options << "EUR"
        all_options = all_options.sort
        return all_options.join(" | ")
  end

Public Instance Methods

base_rate() click to toggle source
# File lib/easy_currency.rb, line 33
def base_rate
        return @base_rate
end
change_base_rate(currency_name) click to toggle source
# File lib/easy_currency.rb, line 14
def change_base_rate(currency_name)
        @exchange_rates = Unirest.get("http://api.fixer.io/latest?base=#{currency_name}").body
        @base_rate = @exchange_rates["base"]
        return @base_rate
end
options_for_base() click to toggle source
# File lib/easy_currency.rb, line 25
def options_for_base
        @options = []
        @exchange_rates["rates"].each do |name, rate|
                @options << name
        end
        return @options.join(" | ")
end
rate_for(currency_name) click to toggle source
# File lib/easy_currency.rb, line 20
def rate_for(currency_name)
        @rate = @exchange_rates["rates"][currency_name]
        return @rate
end