class StockGains::Portfolio

Attributes

total[RW]

Public Class Methods

new() click to toggle source
# File lib/stock-gains/portfolio.rb, line 4
def initialize
  @total = 0
end

Public Instance Methods

calculate_gains() click to toggle source
# File lib/stock-gains/portfolio.rb, line 27
def calculate_gains
  StockGains::Stock.all.collect{ |stock|  @total += stock.days_value } 
  @total = @total.round(2).to_f
end
call() click to toggle source
# File lib/stock-gains/portfolio.rb, line 8
def call 
  list
  calculate_gains
  print_gains
end
extra_spaces() click to toggle source
# File lib/stock-gains/portfolio.rb, line 40
def extra_spaces
  " " * (9 - total.to_s.each_char.count)
end
list() click to toggle source
# File lib/stock-gains/portfolio.rb, line 14
 def list
  puts "\n"
  puts "Stocks in Your Portfolio".center(68)
  puts "\n"
  puts " Stock Name" + " " * 46 + "Today's +/-"
  puts " " + "-" * 67
  StockGains::Stock.all.each.with_index(1) do |stock, i|
    name = stock.name.ljust(55, " ") 
    puts " #{i}. #{name} $#{stock.days_value}"
  end
  puts 
end
print_gains() click to toggle source