class TickerPicker::Ticker

Public Class Methods

get_all_stock_market_prices() click to toggle source

Get all market prices in avaliable stocks

Parameters

  • stock - String which must be a valid stock name

Returns

# File lib/tickerpicker/ticker.rb, line 45
def get_all_stock_market_prices
  stock_market_prices = {}
  stocks.each do |stock_key, _|
    stock_market_prices.merge!({ stock_key => get_all_stock_prices_without_check(stock_key) })
  end
  stock_market_prices
end
get_all_stock_prices(stock) click to toggle source

Get all market prices in a stock

Parameters

  • stock - String which must be a valid stock name

Returns

# File lib/tickerpicker/ticker.rb, line 30
def get_all_stock_prices(stock)
  return stock_does_not_exists unless stocks.has_key?(stock)
  get_all_stock_prices_without_check(stock)
end
get_prices(stock, market) click to toggle source

Get prices for market in stock

Parameters

  • stock - String which must be a valid stock name

  • market - String which should include valid market name

Returns

# File lib/tickerpicker/ticker.rb, line 15
def get_prices(stock, market)
  return stock_market_does_not_exists unless (stocks[stock] || {}).has_key?(market)
  get_price_without_check(stock, market)
end

Private Class Methods

get_all_stock_prices_without_check(stock) click to toggle source

nodoc

# File lib/tickerpicker/ticker.rb, line 65
def get_all_stock_prices_without_check(stock)
  stock_prices = {}
  stocks[stock].each do |key, _|
    stock_prices[key] = get_price_without_check(stock, key)
  end
  stock_prices
end
get_price_without_check(stock, market) click to toggle source

nodoc

# File lib/tickerpicker/ticker.rb, line 60
def get_price_without_check(stock, market)
  TickerPicker::Price.fetch(stock, market)
end
stock_does_not_exists() click to toggle source

nodoc

# File lib/tickerpicker/ticker.rb, line 74
def stock_does_not_exists
  raise StandardError, 'Stock does not exists!'
end
stock_market_does_not_exists() click to toggle source

nodoc

# File lib/tickerpicker/ticker.rb, line 79
def stock_market_does_not_exists
  raise StandardError, 'Stock-market does not exists!'
end
stocks() click to toggle source

nodoc

# File lib/tickerpicker/ticker.rb, line 55
def stocks
  TickerPicker::Configuration.avaliable_stocks
end