Class: YFi::QuoteCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable, HTTParty
Defined in:
lib/y_fi/quote_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tickers) ⇒ YFi::Quote, ...

Returns - an array of Api::ExteralFunds.

Parameters:

  • - (Array<String>)

    An array of tickers, such as [‘AAPL’]



23
24
25
26
27
# File 'lib/y_fi/quote_collection.rb', line 23

def initialize(tickers)
  validate_ticker_format(tickers)
  self.tickers = tickers
  self.raw_quotes = self.class.get("", url_query_options)
end

Instance Attribute Details

#raw_quotesObject

Returns the value of attribute raw_quotes.



12
13
14
# File 'lib/y_fi/quote_collection.rb', line 12

def raw_quotes
  @raw_quotes
end

#tickersObject

Returns the value of attribute tickers.



12
13
14
# File 'lib/y_fi/quote_collection.rb', line 12

def tickers
  @tickers
end

Instance Method Details

#each(&block) ⇒ Object



47
48
49
# File 'lib/y_fi/quote_collection.rb', line 47

def each(&block)
  to_a.each(&block)
end

#find(ticker) ⇒ YFi::Quote

Returns:



43
44
45
# File 'lib/y_fi/quote_collection.rb', line 43

def find(ticker)
  to_a.find{|ef| ef.ticker == ticker.to_s.upcase}
end

#to_aArray

Returns - an array of YFi::Quote.

Returns:

  • (Array)
    • an array of YFi::Quote



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/y_fi/quote_collection.rb', line 30

def to_a
  response_array.each_with_object([]) do |raw_quote, arr|
    next unless valid_quote?(raw_quote)
    arr << Quote.new(
      ticker: raw_quote.fetch("symbol"),
      price: raw_quote["LastTradePriceOnly"].to_f,
      updated_at: parse_updated_at(raw_quote.fetch("LastTradeDate")),
      issuer_name: raw_quote.fetch("Name")
    )
  end
end