Class: StocktickerCli::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



4
5
6
# File 'lib/stockticker_cli/cli.rb', line 4

def call
    welcome 
end

#goodbyeObject



79
80
81
82
83
# File 'lib/stockticker_cli/cli.rb', line 79

def goodbye
    puts "Happy Trading"
    sleep(1)
    puts "Goodbye!"
end


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stockticker_cli/cli.rb', line 18

def menu
    puts "Would you like to view the top gainers in the stock market today?"
    sleep(1)
    puts ""
    puts "Type 'yes' to view gainers or type 'exit' to quit the cli app"
    puts ""

    input = gets.strip.downcase

    if input == 'exit'
        goodbye
    elsif input == 'yes' 
        # API call 
        puts ""
        stock_query = StocktickerCli::API.query
        
        # Return 
        puts "Pick a stock from the list"
        puts ""
        puts "Gainers List:"
        StocktickerCli::STOCK.all.each.with_index(1) do |s, i|
            puts "#{i}. #{s.ticker} - #{s.companyName} - $#{s.price} - #{s.changesPercentage}" 
        end 

        puts ""
        submenu
    else 
        puts "Try again"
        puts ""
        menu
    end 
end


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/stockticker_cli/cli.rb', line 51

def submenu 
        puts "Type a number between '1 - 10' on gainers list for more information on the stock."
        sleep(1)
        
        input = gets.strip.to_i
     
        if (input.between?(0, 10))
            s = StocktickerCli::STOCK.all[input - 1]
            StocktickerCli::API.info_query(s) 
            puts ""       
            puts "#{s.symbol} - #{s.companyName} - $#{s.price}"
            puts ""
            puts "Change: $ #{s.changes}"
            puts "Sector: #{s.sector}"
            puts "Industry: #{s.industry}"
            puts "Website: #{s.website}"
            puts ""
            puts "Description: #{s.description}"
            puts ""
            sleep(1.5)
            StocktickerCli::STOCK.reset 
            menu
        else
          puts "Please try again"
          submenu
        end
end

#welcomeObject



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

def welcome 
    puts "Welcome to the stock ticker cli app!"
    puts ""
    puts "Please sign-up for a free account to use this app here: https://fmpcloud.io/register"
    sleep(1)
    puts "Please enter your api key to continue."
    $KEY = gets.strip
    menu 
end