Class: Alphavantage::Exchange

Inherits:
Object
  • Object
show all
Includes:
HelperFunctions
Defined in:
lib/Exchange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HelperFunctions

#check_argument, #method_missing, #recreate_metadata_key, #return_client, #return_int_val, #return_matype, #return_series, #return_value

Constructor Details

#initialize(from:, to:, key:, verbose: false) ⇒ Exchange

Returns a new instance of Exchange.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/Exchange.rb', line 5

def initialize from:, to:, key:, verbose: false
  check_argument([true, false], verbose, "verbose")
  @client = return_client(key, verbose)
  @from = from
  @to = to
  @hash = @client.request("function=CURRENCY_EXCHANGE_RATE&from_currency=#{@from}&to_currency=#{@to}")
  hash = @hash["Realtime Currency Exchange Rate"]
  hash.each do |key, val|
    key_sym = (key)
    define_singleton_method(key_sym) do
      return val
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HelperFunctions

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



20
21
22
# File 'lib/Exchange.rb', line 20

def hash
  @hash
end