Class: Alphavantage::Exchange
- Inherits:
-
Object
- Object
- Alphavantage::Exchange
- Includes:
- HelperFunctions
- Defined in:
- lib/Exchange.rb
Instance Attribute Summary collapse
-
#datatype ⇒ Object
Returns the value of attribute datatype.
-
#from ⇒ Object
Returns the value of attribute from.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(from:, to:, key:, verbose: false, datatype: "json") ⇒ Exchange
constructor
A new instance of Exchange.
- #now(datatype: @datatype, file: nil) ⇒ Object
- #timeseries(from: @from, to: @to, type: "intraday", file: nil, datatype: @datatype, interval: nil, outputsize: "compact") ⇒ Object
Methods included from HelperFunctions
#check_argument, #check_datatype, #method_missing, #open_struct, #recreate_metadata_key, #return_client, #return_int_val, #return_matype, #return_series, #return_value, #which_series
Constructor Details
#initialize(from:, to:, key:, verbose: false, datatype: "json") ⇒ Exchange
Returns a new instance of Exchange.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/Exchange.rb', line 5 def initialize from:, to:, key:, verbose: false, datatype: "json" check_argument([true, false], verbose, "verbose") @client = return_client(key, verbose) from = from.symbol if from.is_a?(Alphavantage::Crypto) to = to.symbol if to.is_a?(Alphavantage::Crypto) @from = from @to = to check_argument(["json", "csv"], datatype, "datatype") @datatype = datatype end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HelperFunctions
Instance Attribute Details
#datatype ⇒ Object
Returns the value of attribute datatype.
18 19 20 |
# File 'lib/Exchange.rb', line 18 def datatype @datatype end |
#from ⇒ Object
Returns the value of attribute from.
17 18 19 |
# File 'lib/Exchange.rb', line 17 def from @from end |
#to ⇒ Object
Returns the value of attribute to.
17 18 19 |
# File 'lib/Exchange.rb', line 17 def to @to end |
Instance Method Details
#now(datatype: @datatype, file: nil) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/Exchange.rb', line 25 def now(datatype: @datatype, file: nil) url = "function=CURRENCY_EXCHANGE_RATE&from_currency=#{@from}&to_currency=#{@to}" check_datatype(datatype, file) return @client.download(url, file) if datatype == "csv" return open_struct(url, "Realtime Currency Exchange Rate") end |
#timeseries(from: @from, to: @to, type: "intraday", file: nil, datatype: @datatype, interval: nil, outputsize: "compact") ⇒ Object
32 33 34 35 |
# File 'lib/Exchange.rb', line 32 def timeseries from: @from, to: @to, type: "intraday", file: nil, datatype: @datatype, interval: nil, outputsize: "compact" Alphavantage::Exchange_Timeseries.new from: from, to: to, type: type, datatype: datatype, file: file, key: @client, interval: interval, outputsize: outputsize end |