class Portfolio

Attributes

capital[RW]
cash[RW]
invested[RW]

Public Class Methods

new(capital) click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 5
def initialize(capital)
  
  @capital = capital
  @cash = capital
  invested

end

Public Instance Methods

create_or_buy_more(stock_hash, amount) click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 50
def create_or_buy_more(stock_hash, amount)

  @cash -= amount
  @invested += amount
  Stock.create_or_buy_more(stock_hash, amount)

end
deposit(amount) click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 67
def deposit(amount)

  @cash += amount
  @capital += amount

end
display() click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 37
def display
  
  self.update
  puts "Amount invested = $#{self.invested}"
  puts "Cash availible = $#{self.cash}"
  if (!stocks.empty?)

    stocks.each{|stock|stock.display}

  end


end
sell_stock(ticker, amount) click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 58
def sell_stock(ticker, amount)


  Stock.sell(ticker, amount)
  @invested -= amount
  @cash += amount
  
end
stocks() click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 13
def stocks

  Stock.all

end
update() click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 19
def update

  if !(stocks.empty?)
    value_change = Stock.update_stocks
    @invested += value_change
    @capital += value_change
    
  end

end
withdraw(amount) click to toggle source
# File lib/portfolio_maker/portfolio.rb, line 74
def withdraw(amount)

  @cash -= amount
  @capital -= amount       

end