class Stocks::Quote

Reprsents an instance of a stock quote.

Constants

TYPES

Mapping from base_quote type to YahooFinance method of retrieval (options: :extended, :standard)

Public Class Methods

get(symbols, type = :standard) click to toggle source

Fetches a quote for the provided symbols.

Args
  • symbols The symbols for which to retrieve a quote

  • type The type of quote to retreive (default: :standard)

Returns

The quote for the provided symbol

Raises
  • UnsupportedError If the provided type is not supported

# File lib/stocks/quote.rb, line 23
def self.get(symbols, type = :standard)
  raise UnsupportedError.new(type, Quote::TYPES.keys) if !Quote::TYPES.has_key?(type)

  symbols = [symbols] if !symbols.is_a?(Array)
  symbols = symbols.collect { |s| s.upcase }

  quotes = YahooFinance.send(Quote::TYPES[type], symbols)
  quotes.each_pair { |symbol, quote| quotes[symbol] = Quote.new(quote) }

  quotes
end