Class: StockMarkit::Lookup
- Inherits:
-
Object
- Object
- StockMarkit::Lookup
- Includes:
- HTTParty
- Defined in:
- lib/stock-markit/lookup.rb
Overview
Lookup a Stock by Symbol
- Copyright
-
Copyright © 2016 Michael Heijmans
- License
-
MIT
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Options hash for httparty.
-
#results ⇒ Array<StockMarkit::Stock>
readonly
The stocks that match the symbol.
-
#symbol ⇒ String, Symbol
readonly
The symbol of the stock to lookup.
Instance Method Summary collapse
-
#fetch ⇒ Array<StockMarkit::Stock>
Fetch stocks matching @symbol from the api.
-
#initialize(symbol) ⇒ Lookup
constructor
A new instance of Lookup.
Constructor Details
#initialize(symbol) ⇒ Lookup
Returns a new instance of Lookup.
25 26 27 28 |
# File 'lib/stock-markit/lookup.rb', line 25 def initialize(symbol) @symbol = symbol.to_sym.upcase @options = { query: {input: @symbol} } end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Options hash for httparty
18 19 20 |
# File 'lib/stock-markit/lookup.rb', line 18 def @options end |
#results ⇒ Array<StockMarkit::Stock> (readonly)
The stocks that match the symbol. This is populated on the first call of <#fetch>
18 19 20 |
# File 'lib/stock-markit/lookup.rb', line 18 def results @results end |
#symbol ⇒ String, Symbol (readonly)
The symbol of the stock to lookup
18 19 20 |
# File 'lib/stock-markit/lookup.rb', line 18 def symbol @symbol end |
Instance Method Details
#fetch ⇒ Array<StockMarkit::Stock>
Fetch stocks matching @symbol from the api
This method memoizes the results and returns the contents of the results variable instead of asking the api again
35 36 37 |
# File 'lib/stock-markit/lookup.rb', line 35 def fetch @results ||= lookup_with_api end |