Class: StockScraper::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/stock_scraper/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



4
5
6
7
8
# File 'lib/stock_scraper/cli.rb', line 4

def call
  list_stocks
  menu
  goodbye
end

#goodbyeObject



46
47
48
# File 'lib/stock_scraper/cli.rb', line 46

def goodbye
  puts "See you tomorrow for more stock information"
end

#list_stocksObject



10
11
12
13
14
15
16
# File 'lib/stock_scraper/cli.rb', line 10

def list_stocks
  puts "Today's popular trending stocks are:"
  update_stocks
  @stocks.each.with_index(1) do |stock, i|
    puts "#{i}. #{stock.name}"
  end
end


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/stock_scraper/cli.rb', line 22

def menu
  input = nil
  while input != "exit"
    puts "Enter the number of the stock you would like more information on or type list to see more stocks or type exit"
    input = gets.strip.downcase
    if input.to_i > 0 && input.to_i - 1 < @stocks.length
      update_stocks
      the_stock = @stocks[input.to_i - 1]
      puts ""
      puts "Stock Name: #{the_stock.name} - Symbol: #{the_stock.symbol}"
      puts "Last Price: $#{the_stock.last_price} - Market Time: #{the_stock.market_time} - Change Percent: #{the_stock.change_percent}"
      puts ""
    elsif input == "list"
      list_stocks
    elsif input == "exit"
      puts "Happy trading!"
    elsif  input.to_i >= @stocks.length - 1
      puts "Not sure what stock you are requesting, type list or exit"
    else
      puts "you have found a vulnerability; hacking into the main frame!"
    end
  end
end

#update_stocksObject



18
19
20
# File 'lib/stock_scraper/cli.rb', line 18

def update_stocks
  @stocks = StockScraper::Stock.scrape_yahoo
end