Class: CryptoMarket::CLI
- Inherits:
-
Object
- Object
- CryptoMarket::CLI
- Includes:
- CryptoMarket
- Defined in:
- lib/crypto_market/cli.rb
Constant Summary
Constants included from CryptoMarket
Instance Attribute Summary collapse
-
#currencies ⇒ Object
Returns the value of attribute currencies.
Instance Method Summary collapse
- #enter_input_msg ⇒ Object
- #enter_valid_input_msg ⇒ Object
-
#greeting ⇒ Object
Greeting message.
-
#initialize ⇒ CLI
constructor
Initialize the CLI with an instance of all currencies.
-
#navigation ⇒ Object
User navigation.
-
#run ⇒ Object
Run command to start the program.
Methods included from CryptoMarket
Constructor Details
#initialize ⇒ CLI
Initialize the CLI with an instance of all currencies
6 7 8 |
# File 'lib/crypto_market/cli.rb', line 6 def initialize @currencies = CryptoMarket::Currencies.new end |
Instance Attribute Details
#currencies ⇒ Object
Returns the value of attribute currencies.
3 4 5 |
# File 'lib/crypto_market/cli.rb', line 3 def currencies @currencies end |
Instance Method Details
#enter_input_msg ⇒ Object
30 31 32 |
# File 'lib/crypto_market/cli.rb', line 30 def enter_input_msg print 'Enter a number: ' end |
#enter_valid_input_msg ⇒ Object
26 27 28 |
# File 'lib/crypto_market/cli.rb', line 26 def enter_valid_input_msg puts 'Enter a correct number from the list' end |
#greeting ⇒ Object
Greeting message
18 19 20 21 22 23 24 |
# File 'lib/crypto_market/cli.rb', line 18 def greeting <<-DOC Welcome to the Crypto Market All the prices are updated every 5 minutes Enter a number to navigate DOC end |
#navigation ⇒ Object
User navigation
35 36 37 38 39 40 41 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/crypto_market/cli.rb', line 35 def table = terminal_table do |t| t.title = greeting t.add_row [1, 'Get more information about a specific coin'] t.add_row [2, 'Sort by price'] t.add_row [3, 'Sort by price change the last 24h'] t.add_row [4, 'To exit the program'] t.style = { all_separators: true, width: 60 } end puts table enter_input_msg input = gets.strip.to_i loop do case input when 1 coin_search when 2 currencies.print_sorted_prices when 3 table = terminal_table do |t| t.title = 'Select a number' t.add_row [1, '(+) Changed coins the last 24h'] t.add_row [2, '(-) Changed coins the last 24h'] t.add_row [3, 'All Changed coins the last 24h'] t.style = { all_separators: true, width: 60 } end input = nil until input == 1 || input == 2 || input == 3 puts table enter_input_msg input = gets.strip.to_i if input == 1 currencies.print_sorted_changes('positive') elsif input == 2 currencies.print_sorted_changes('negative') elsif input == 3 currencies.print_sorted_changes else enter_valid_input_msg end end when 4 puts "Goodbye you're now closing Crypto Market!" exit else enter_valid_input_msg end end end |
#run ⇒ Object
Run command to start the program
11 12 13 14 15 |
# File 'lib/crypto_market/cli.rb', line 11 def run currencies.run puts ascii_welcome end |