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


20
21
22
23
# File 'lib/stock-markit/lookup.rb', line 20

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


13
14
15
# File 'lib/stock-markit/lookup.rb', line 13

def options
  @options
end

#resultsArray<StockMarkit::Stock> (readonly)

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

Returns:


13
14
15
# File 'lib/stock-markit/lookup.rb', line 13

def results
  @results
end

#symbolString, Symbol (readonly)

The symbol of the stock to lookup

Returns:

  • (String, Symbol)

    the current value of symbol


13
14
15
# File 'lib/stock-markit/lookup.rb', line 13

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:


30
31
32
# File 'lib/stock-markit/lookup.rb', line 30

def fetch
  @results ||= lookup_with_api
end