Class: StockMarkit::Lookup

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/stock-markit/lookup.rb

Overview

Lookup a Stock by Symbol

Copyright

Copyright © 2016 Michael Heijmans

License

MIT

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol) ⇒ Lookup

Returns a new instance of Lookup.

Parameters:

  • symbol (String, Symbol)

    The stock’s ticker symbol



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

#optionsHash (readonly)

Options hash for httparty

Returns:

  • (Hash)

    the current value of options



18
19
20
# File 'lib/stock-markit/lookup.rb', line 18

def options
  @options
end

#resultsArray<StockMarkit::Stock> (readonly)

The stocks that match the symbol. This is populated on the first call of <#fetch>

Returns:



18
19
20
# File 'lib/stock-markit/lookup.rb', line 18

def results
  @results
end

#symbolString, Symbol (readonly)

The symbol of the stock to lookup

Returns:

  • (String, Symbol)

    the current value of symbol



18
19
20
# File 'lib/stock-markit/lookup.rb', line 18

def symbol
  @symbol
end

Instance Method Details

#fetchArray<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

Returns:



35
36
37
# File 'lib/stock-markit/lookup.rb', line 35

def fetch
  @results ||= lookup_with_api
end