class StockGains::Stock

Attributes

cur_price[RW]
d_range[RW]
days_value[RW]
eps[RW]
name[RW]
open[RW]
pe[RW]
prev_close[RW]
shares[RW]
y_range[RW]
year_trgt[RW]

Public Class Methods

all() click to toggle source
# File lib/stock-gains/stock.rb, line 19
def self.all 
  @@all ||= create_stock_from_portfolio
end
create_stock_from_portfolio() click to toggle source
# File lib/stock-gains/stock.rb, line 27
def self.create_stock_from_portfolio
  CSV.foreach("portfolio.csv").collect do |stock|
    s = (retrieve_stock(stock) << stock[1]).flatten
    new(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9])
  end
end
new(name, cur_price, prev_close, open, year_trgt, d_range, y_range, pe, eps, shares) click to toggle source
# File lib/stock-gains/stock.rb, line 5
def initialize(name, cur_price, prev_close, open, year_trgt, d_range, y_range, pe, eps, shares)
  @name = name
  @cur_price = cur_price
  @prev_close = prev_close
  @open = open
  @year_trgt = year_trgt
  @d_range = d_range
  @y_range = y_range
  @pe = pe
  @eps = eps
  @shares = shares
  calculate_days_value
end
retrieve_stock(stock) click to toggle source
# File lib/stock-gains/stock.rb, line 34
def self.retrieve_stock(stock)
  url = "http://finance.yahoo.com/d/quotes.csv?s=#{stock.first}&f=napot8mwre"
  open(url) do |csv|
    CSV.parse(csv).collect{ |row| row }
  end
end

Public Instance Methods

calculate_days_value() click to toggle source
# File lib/stock-gains/stock.rb, line 23
def calculate_days_value
  @days_value = ((cur_price.to_f * shares.to_f) - (prev_close.to_f * shares.to_f)).round(2).to_f 
end