Class: Cli
- Inherits:
-
Object
- Object
- Cli
- Defined in:
- lib/services/cli.rb
Instance Method Summary collapse
- #get_input ⇒ Object
- #main_menu ⇒ Object
- #main_menu_options ⇒ Object
-
#standardize_crypto_name_length ⇒ Object
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.
- #start ⇒ Object
Instance Method Details
#get_input ⇒ Object
68 69 70 |
# File 'lib/services/cli.rb', line 68 def get_input gets.chomp end |
#main_menu ⇒ Object
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 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 "" end |
#main_menu_options ⇒ Object
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 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 "" 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) end end |
#standardize_crypto_name_length ⇒ Object
if exit_option == “Y”
puts ""
puts "Closing program..."
puts ""
elsif exit_option == "N"
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 |
#start ⇒ Object
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 end |