class PortfolioMaker::CommandLineInterface
Attributes
user_portfolio[RW]
Public Instance Methods
most_active()
click to toggle source
# File lib/portfolio_maker/command_line_interface.rb, line 98 def most_active puts "Printing top 10 trending stocks" Scraper.scrap_trending_stocks_page end
run()
click to toggle source
# File lib/portfolio_maker/command_line_interface.rb, line 5 def run capital = 0 loop do puts "How much would you like to deposit into your account?" capital = gets.chomp break if ((capital.to_i > 0) && capital.scan(/\D/).empty?) puts "Please enter correct value" end @user_portfolio = Portfolio.new(capital.to_i) main_menu end
stock_find()
click to toggle source
# File lib/portfolio_maker/command_line_interface.rb, line 52 def stock_find stock_info = {} #binding.pry loop do puts "Please enter stock ticker" ticker = gets.chomp if (!Stock.find_stock_with_ticker(ticker)) stock_info = Scraper.scrape_stock_page("https://finance.yahoo.com/quote/" + ticker) else stock_info = Stock.find_stock_with_ticker(ticker).make_hash_from_stock end break if (stock_info != nil) puts "Please enter a proper stock ticker (No ETFs, Crypto, Indexes etc.)" end puts "Name: #{stock_info[:name]}, Price: $#{stock_info[:price]}, market cap: $#{stock_info[:market_cap]}" puts "Select one of the following options by entering one of the below option number in your ternminal:" puts "1. Add stock to portfolio or buy more" puts "2. Return to main menu" input = menu_input(2) #binding.pry case input when 1 amount = 0 loop do puts "Select what amount would you like to buy?\n current cash = $#{user_portfolio.cash}" amount = gets.chomp break if (!(amount.to_i > user_portfolio.cash || amount.to_i <= 0) && amount.scan(/\D/).empty?) puts "Please enter valid amount within availible cash" end #binding.pry user_portfolio.create_or_buy_more(stock_info, amount.to_i) #binding.pry puts "Bought #{amount.to_i / stock_info[:price].gsub(/[\s,]/ ,"").to_f} shares of #{stock_info[:name]}" when 2 end end