Class: YFi::QuoteCollection
- Inherits:
-
Object
- Object
- YFi::QuoteCollection
- Includes:
- Enumerable, HTTParty
- Defined in:
- lib/y_fi/quote_collection.rb
Instance Attribute Summary collapse
-
#raw_quotes ⇒ Object
Returns the value of attribute raw_quotes.
-
#tickers ⇒ Object
Returns the value of attribute tickers.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #find(ticker) ⇒ YFi::Quote
-
#initialize(tickers) ⇒ YFi::Quote, ...
constructor
-
an array of Api::ExteralFunds.
-
-
#to_a ⇒ Array
-
an array of YFi::Quote.
-
Constructor Details
#initialize(tickers) ⇒ YFi::Quote, ...
Returns - an array of Api::ExteralFunds.
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("", ) end |
Instance Attribute Details
#raw_quotes ⇒ Object
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 |
#tickers ⇒ Object
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
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_a ⇒ Array
Returns - 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 |