Class: Main_menu
- Inherits:
-
Object
- Object
- Main_menu
- Defined in:
- lib/classes/Main_menu.rb
Constant Summary collapse
- @@pokemon_data =
Creates an array of hashes from the CSV file with keys taken from CSV headers.
SmarterCSV.process(File.("../pokemon.csv", __FILE__))
Class Method Summary collapse
- .delete_pokemon ⇒ Object
- .exit_menu ⇒ Object
- .list_pokemon ⇒ Object
- .new_pokemon ⇒ Object
- .return? ⇒ Boolean
- .run ⇒ Object
- .search_pokemon ⇒ Object
- .update_pokemon ⇒ Object
Class Method Details
.delete_pokemon ⇒ Object
81 82 83 |
# File 'lib/classes/Main_menu.rb', line 81 def self.delete_pokemon @@pokemon_data = Delete.delete(@@pokemon_data) end |
.exit_menu ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/classes/Main_menu.rb', line 85 def self. = TTY::Prompt.new(active_color: :red) save_changes = .ask('Are you sure you want to save your changes?') if save_changes == true CSV.open(File.("../pokemon.csv", __FILE__), 'wb') do |csv| keys = @@pokemon_data.first.keys csv << keys @@pokemon_data.each do |hash| csv << hash.values_at(*keys) end end exit else exit end end |
.list_pokemon ⇒ Object
63 64 65 |
# File 'lib/classes/Main_menu.rb', line 63 def self.list_pokemon List.(@@pokemon_data) end |
.new_pokemon ⇒ Object
75 76 77 78 79 |
# File 'lib/classes/Main_menu.rb', line 75 def self.new_pokemon new_hash = New.add_pokemon @@pokemon_data << new_hash Print.(new_hash) end |
.return? ⇒ Boolean
57 58 59 60 61 |
# File 'lib/classes/Main_menu.rb', line 57 def self.return? puts 'Press enter to return to the Main Menu.' user_input = gets.chomp run end |
.run ⇒ Object
16 17 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 50 51 52 53 54 55 |
# File 'lib/classes/Main_menu.rb', line 16 def self.run loop do system 'clear' sleep 0.1 fork { exec "artii 'Pokedex' --font larry3d | lolcat" } sleep(0.3) = TTY::Prompt.new(active_color: :red) puts '-' * 40 puts ' Welcome to your Pokedex! '.blue.on_red.blink puts '-' * 40 user_input = .select('Please select from the following:') do || .choice 'List Pokemon', 1 .choice 'Search for a Pokemon', 2 .choice 'Update an existing Pokemon', 3 .choice 'Add a new Pokemon', 4 .choice 'Delete a Pokemon', 5 .choice 'Exit and save changes', 6 # menu.choice 'Print hashes', 7 end case user_input when 1 list_pokemon when 2 search_pokemon when 3 update_pokemon when 4 new_pokemon when 5 delete_pokemon when 6 # uncomment below 2 lines to allow developer feature to check hashes # when 7 # pp @@pokemon_data else 'Invalid selection, please select from the following options.' end end end |
.search_pokemon ⇒ Object
67 68 69 |
# File 'lib/classes/Main_menu.rb', line 67 def self.search_pokemon Print.(Search.return_hash(@@pokemon_data, Search.by_name(@@pokemon_data))) end |
.update_pokemon ⇒ Object
71 72 73 |
# File 'lib/classes/Main_menu.rb', line 71 def self.update_pokemon Update.(@@pokemon_data) end |