class StocksInfo::CLI
Public Instance Methods
open_twits(ticker)
click to toggle source
# File lib/stocks-info/cli.rb, line 77 def open_twits(ticker) system("open #{StocksInfo::Stocktwits.new(ticker).url}") end
show_indices()
click to toggle source
# File lib/stocks-info/cli.rb, line 9 def show_indices puts "Here is how the market is doing today" {"S&P500": "%5EGSPC", "DOW JONES": "%5EDJI", "NASDAQ": "%5EIXIC"}.each do |name, ticker| index = StocksInfo::Ticker.new(ticker) StocksInfo::Scraper.scrape(index) puts "#{name}: #{index.price}, #{index.price_change}" end end
show_news(ticker)
click to toggle source
# File lib/stocks-info/cli.rb, line 49 def show_news(ticker) StocksInfo::Scraper.scrape(ticker) puts "Latest News for #{ticker.name}:" ticker.news.each_with_index do |title, index| puts "#{index + 1}. #{title.text}" ticker.links << title.attribute("href").value end puts "Do you want to view any of these articles? Type its number or else type no" input = nil while input != "no" input= gets.strip if input == "no" puts "exiting to main menu" elsif input.to_i <= ticker.links.length && input.to_i > 0 #strings will convert to 0 system("open https://finance.yahoo.com#{ticker.links[input.to_i - 1]}") else puts "That is not a valid article." end end ticker.links.clear end
show_price(ticker)
click to toggle source
# File lib/stocks-info/cli.rb, line 70 def show_price(ticker) StocksInfo::Scraper.scrape(ticker) puts ticker.name puts ticker.price puts ticker.price_change end
show_trending()
click to toggle source
# File lib/stocks-info/cli.rb, line 18 def show_trending message = "Trending on Stocktwits:" StocksInfo::Scraper.scrape_trending StocksInfo::Stocktwits.trending_tickers.each do |ticker| message += " #{ticker}" end puts message end
start()
click to toggle source
# File lib/stocks-info/cli.rb, line 3 def start show_indices show_trending menu end