Class: BasicYahooFinance::Util
- Inherits:
-
Object
- Object
- BasicYahooFinance::Util
- Defined in:
- lib/basic_yahoo_finance/util.rb
Overview
Small useful utility methods
Class Method Summary collapse
-
.find_fx_symbol(quotes, currency1, currency2) ⇒ Object
Find correct FX symbol in quotes as the symbol format can vary.
-
.generate_currency_symbols(currencies, base_currency) ⇒ Object
Generate currency symbols array based on array of currencies and base currency.
-
.generate_fx_symbol(currency1, currency2) ⇒ Object
Generate symobol for foreign exchange rate lookup.
Class Method Details
.find_fx_symbol(quotes, currency1, currency2) ⇒ Object
Find correct FX symbol in quotes as the symbol format can vary
7 8 9 10 11 12 13 14 |
# File 'lib/basic_yahoo_finance/util.rb', line 7 def self.find_fx_symbol(quotes, currency1, currency2) # Exception for USDCHF=X symbol as it is sometimes returned as CHF=X if currency1 == "USD" && currency2 == "CHF" quotes["USDCHF=X"].nil? ? "CHF=X" : "#{currency1}CHF=X" else "#{currency1}#{currency2}=X" end end |
.generate_currency_symbols(currencies, base_currency) ⇒ Object
Generate currency symbols array based on array of currencies and base currency
17 18 19 20 21 22 23 24 25 |
# File 'lib/basic_yahoo_finance/util.rb', line 17 def self.generate_currency_symbols(currencies, base_currency) currency_symbols = [] currencies.each do |currency| next if currency == base_currency currency_symbols.push("#{currency}#{base_currency}=X") end currency_symbols end |
.generate_fx_symbol(currency1, currency2) ⇒ Object
Generate symobol for foreign exchange rate lookup
28 29 30 31 32 33 34 35 |
# File 'lib/basic_yahoo_finance/util.rb', line 28 def self.generate_fx_symbol(currency1, currency2) # Exception for USD against CHF which is formatted as 'CHF=X' if currency1 == "USD" && currency2 == "CHF" "#{currency2}=X" else "#{currency1}/#{currency2}" end end |