Class: Cli

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

Instance Method Summary collapse

Instance Method Details

#get_inputObject



68
69
70
# File 'lib/services/cli.rb', line 68

def get_input
    gets.chomp
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/services/cli.rb', line 17

def main_menu
    col1 = 0
    col2 = 25
    col3 = 50
    col4 = 75

    standardize_crypto_name_length

    puts ""
    puts " --- Top 100 Cryptocurrencies --- ".green
    puts ""
    while col1 < 25
        puts " #{col1 + 1}. #{CryptoStats.all[col1].name} \t\t #{col2 + 1}. #{CryptoStats.all[col2].name} \t\t #{col3 + 1}. #{CryptoStats.all[col3].name} \t\t #{col4 + 1}. #{CryptoStats.all[col4].name}"
        
        col1 += 1
        col2 += 1
        col3 += 1
        col4 += 1
    end

    puts ""

    main_menu_options
end


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/services/cli.rb', line 42

def main_menu_options
    print "Enter the Cryptocurrency number to view more details or type 'exit' to leave the program: ".green
    option = get_input

    if option == "exit"
        puts ""
        puts "Closing program..."
        puts ""
    elsif option.to_i - 1 < 0 || option.to_i - 1 > 99
        puts "Invalid entry. Please try again...".red
        puts ""
        main_menu_options
    else
        puts ""
        CryptoStats.all[option.to_i - 1].display_stats
        puts ""
        puts "Press the 'Enter' key to continue...".green
        gets.chomp
        puts " ~~> fetching data from CoinGecko...".blue
        sleep(1)
        puts " ~~> loading the top 100 cryptocurrencies...".blue
        sleep(1)
        main_menu
    end
end

#standardize_crypto_name_lengthObject

if exit_option == “Y”

    puts ""
    puts "Closing program..."
    puts ""
elsif exit_option == "N"
    main_menu
else
    puts "Invalid entry! Please try again..".red
    puts ""
    exit?
end

end



89
90
91
92
93
94
95
96
97
# File 'lib/services/cli.rb', line 89

def standardize_crypto_name_length
    max_length = 25

    CryptoStats.all.each do |crypto|
        while crypto.name.length < max_length
            crypto.name += " "
        end
    end
end

#startObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/services/cli.rb', line 3

def start
    puts ""
    puts "---------------------------------------------".yellow
    puts "---------- Welcome to CryptoStats! ----------".yellow
    puts "---------------------------------------------".yellow
    puts ""
    puts " ~~> fetching data from CoinGecko...".blue
    sleep(1)
    puts " ~~> loading the top 100 cryptocurrencies...".blue
    sleep(1)
    Api.load_data
    main_menu
end