class StockGains::CLI

Public Instance Methods

call() click to toggle source
# File lib/stock-gains/cli.rb, line 4
def call
  begin
    StockGains::Portfolio.new.call
    start
  rescue
    puts "\n\nTo upload your portfolio to Stock Gains, see installation at:"
    puts "https://github.com/frankNowinski/stock-gains\n\n"
    stock_lookup
  end 
  puts "\nGoodbye!"
end
find(input) click to toggle source
# File lib/stock-gains/cli.rb, line 40
def find(input)
  print_stock_info(input.map(&:to_i).collect{ |s| StockGains::Stock.all[s-1] })
end
find_all() click to toggle source
# File lib/stock-gains/cli.rb, line 36
def find_all
  print_stock_info(StockGains::Stock.all)
end
print_stock_info(stocks) click to toggle source
start() click to toggle source
# File lib/stock-gains/cli.rb, line 16
def start
  input = ""
  begin
    puts "\nTo view more stock information, enter the number associated with"
    puts "the stock name in your portfolio or enter 'all' to display all."
    puts "Separate digits with a space to view multiple stocks."
    puts "(Enter 'e' at anytime throughout the program to exit)\n\n"
    input = gets.strip.downcase.scan(/\w+/)
  end until valid_input?(input) || input.first == "e"
  
  if input.first != "e" 
    input.first == "all" ? find_all : find(input)
    stock_lookup
  end
end
stock_lookup() click to toggle source
# File lib/stock-gains/cli.rb, line 58
def stock_lookup
  StockGains::StockLookup.new.call
end
valid_input?(input) click to toggle source
# File lib/stock-gains/cli.rb, line 32
def valid_input?(input)
  input.first == "all" || input.map(&:to_i).all?{ |n| n.between?(1, StockGains::Stock.all.count)}
end