class StockInquiry::CLI
Attributes
stock[R]
ticker[R]
ticker_list[R]
Public Class Methods
new()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 4 def initialize @ticker_list = File.readlines("./lib/stock_inquiry/stock_ticker_092017.txt").map { |ticker| ticker.chomp }.sort end
Public Instance Methods
exit_program()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 137 def exit_program puts "" puts "Thank you for using stock inquiry" exit end
list_articles()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 98 def list_articles puts "" @stock.articles.each.with_index(1) do |article, idx| puts "#{idx}. #{article.title}" end if @stock.articles == [] puts "There are no latest news posted in the site" puts "Please enter more to look for further information" else show_article end end
list_current_price()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 74 def list_current_price puts "" puts @stock.current_price end
list_open_price()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 79 def list_open_price puts "" puts @stock.open_price end
list_previous_price()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 84 def list_previous_price puts "" puts @stock.previous_close end
list_range()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 89 def list_range puts "" puts @stock.range end
more()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 129 def more system("open https://www.reuters.com/finance/stocks/overview/#{ticker}") end
obtain_ticker()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 17 def obtain_ticker puts "Please enter stock/security ticker symbol" @ticker = gets.upcase.strip end
restart()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 133 def restart start end
show_article()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 111 def show_article puts "Enter number of the article you would like to read" input = gets.to_i total_num = @stock.articles.size if !input.between?(1, total_num) puts "Number not found" show_article else system("open https://www.reuters.com#{stock.articles[input - 1].url}") end end
show_chart()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 94 def show_chart system("open http://www.reuters.com/finance/stocks/chart/#{ticker}") end
show_description()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 124 def show_description puts "" puts @stock.description end
start()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 8 def start obtain_ticker valid_ticker? s = StockInquiry::Scraper.new(ticker) s.scrape_all @stock = StockInquiry::Stock.find_by_ticker(ticker) menu end
valid_ticker?()
click to toggle source
# File lib/stock_inquiry/cli.rb, line 22 def valid_ticker? match_ticker = ticker_list.select { |stock| stock == "#{ticker}" } if match_ticker == [] puts "This is not a valid ticker" obtain_ticker end end