Class: GoogleFinance::Quote

Inherits:
Resource
  • Object
show all
Defined in:
lib/google-finance/quote.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(symbol) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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

Instance Method Details

#change_in_percent_sObject



49
50
51
52
53
54
55
# File 'lib/google-finance/quote.rb', line 49

def change_in_percent_s
  [
    change_in_percent > 0 ? '+' : '',
    format('%.2f', change_in_percent),
    '%'
  ].join
end