class GoogleFinance::Company

Google Company class

Attributes

employees[RW]
name[RW]
prices[RW]
ticker[RW]

Public Class Methods

new(ticker) click to toggle source

get the ticker with the initialize

# File lib/GoogleFinance/Company.rb, line 16
def initialize(ticker)
  @ticker = ticker
end

Public Instance Methods

get_historical_prices(date_start, date_end) click to toggle source

load the historical prices iwth the current ticker

# File lib/GoogleFinance/Company.rb, line 45
def get_historical_prices(date_start, date_end)

  @prices = GoogleFinance::HistoricalPrices.new(@ticker, date_start, date_end)

end
shares() click to toggle source

get the outstanding share count

# File lib/GoogleFinance/Company.rb, line 53
def shares
  return @shares unless @shares.nil?

  name_url = "https://google.com/finance?q=" + @ticker
  page     = Nokogiri::HTML(open(name_url))
  share    = page.xpath("//table[@class='snap-data']/tr[3]/td")[3].inner_html.gsub(/\n|,|-/, "")

  # if the thing says 'M' then it's million, if it's 'B' then billions, obviously
  if    share.match(/M$/) then
    @shares = share.gsub("M", "").to_f
  elsif share.match(/B$/) then
    @shares = share.gsub("B", "").to_f * 1000
  end
  @shares
end