class GoogleFinance::Quote

Public Class Methods

get(symbol) click to toggle source
# File lib/google-finance/quote.rb, line 57
def self.get(symbol)
  data = GoogleFinance::Api::Index.get(q: symbol)
  if data.is_a?(Hash) && data.key?('searchresults')
    if data['searchresults'].size >= 1
      get(data['searchresults'].first['symbol'])
    else
      raise GoogleFinance::Errors::SymbolNotFoundError.new(symbol, data)
    end
  elsif data.is_a?(Array) && data.size == 1
    new data.first
  else
    raise GoogleFinance::Errors::SymbolNotFoundError.new(symbol, data)
  end
end

Public Instance Methods

change_in_percent_s() click to toggle source
# File lib/google-finance/quote.rb, line 49
def change_in_percent_s
  [
    change_in_percent > 0 ? '+' : '',
    format('%.2f', change_in_percent),
    '%'
  ].join
end