Class: Mondex::CLI
- Inherits:
-
Object
- Object
- Mondex::CLI
- Defined in:
- lib/mondex/cli.rb
Constant Summary collapse
- WEBSITE =
"https://monsterhunterworld.wiki.fextralife.com/Large+Monsters"
Instance Method Summary collapse
- #add_attributes_to_monsters ⇒ Object
- #call ⇒ Object
- #create_monsters ⇒ Object
- #goodbye ⇒ Object
- #invalid_selection ⇒ Object
- #main_menu ⇒ Object
- #pick_monsters(array_of_monsters) ⇒ Object
- #pick_monsters_through_species ⇒ Object
- #print_details(monster) ⇒ Object
- #print_list(array_of_monsters) ⇒ Object
- #print_monsters_details(array_of_monsters) ⇒ Object
- #print_species ⇒ Object
Instance Method Details
#add_attributes_to_monsters ⇒ Object
123 124 125 126 127 128 |
# File 'lib/mondex/cli.rb', line 123 def add_attributes_to_monsters Mondex::Monster.all.each do |monster| attributes = Mondex::Scraper.scrape_monster_page(monster.url) monster.add_attributes(attributes) end end |
#call ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mondex/cli.rb', line 6 def call puts "Getting information from Ecological Research...".colorize(:red) create_monsters puts "Definitely not bribing...".colorize(:red) add_attributes_to_monsters puts "Information retrieved!".colorize(:green) puts "WELCOME TO MONDEX!".colorize(:blue) puts "Your monster hunter 'Pokedex'!" puts "'Know your enemy' before you hunt and carve your spoils!" end |
#create_monsters ⇒ Object
118 119 120 121 |
# File 'lib/mondex/cli.rb', line 118 def create_monsters monster_array = Mondex::Scraper.scrape_list_page(WEBSITE) Mondex::Monster.create_from_list(monster_array) end |
#goodbye ⇒ Object
114 115 116 |
# File 'lib/mondex/cli.rb', line 114 def goodbye puts "Thank you for using Mondex! Happy hunting!".upcase.colorize(:green) end |
#invalid_selection ⇒ Object
110 111 112 |
# File 'lib/mondex/cli.rb', line 110 def invalid_selection puts "Please pick a valid selection".colorize(:red) end |
#main_menu ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mondex/cli.rb', line 19 def puts "Pick the number of your choice.".colorize(:yellow) puts "1. List all monster" puts "2. List all species" puts "3. Exit Mondex :(" choice = gets.strip case choice when "1" pick_monsters(Mondex::Monster.all) when "2" print_species when "3" goodbye exit else invalid_selection end end |
#pick_monsters(array_of_monsters) ⇒ Object
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 90 |
# File 'lib/mondex/cli.rb', line 63 def pick_monsters(array_of_monsters) print_list(array_of_monsters) input = nil while input != 'Exit' puts "Type the number or name of the monster to view its details".colorize(:yellow) puts "'all' to view all monster details".colorize(:yellow) puts "'list' to view the list of monsters".colorize(:yellow) puts "'exit' to go back to main menu".colorize(:yellow) input = gets.strip.split.map {|w| w.capitalize}.join(" ") number_choice = (input.to_i) - 1 monsters = array_of_monsters.select {|m| m.name.include?(input)} if input == "All" print_monsters_details(array_of_monsters) elsif monsters != [] print_monsters_details(monsters) elsif number_choice.between?(0, array_of_monsters.count - 1) print_details(array_of_monsters[number_choice]) elsif input == 'List' print_list(array_of_monsters) else invalid_selection end end end |
#pick_monsters_through_species ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mondex/cli.rb', line 97 def pick_monsters_through_species puts "Pick a number to show all monsters that belong to that species".colorize(:yellow) input = (gets.strip.to_i) - 1 if input.between?(0, Mondex::Species.all.count - 1) monsters = Mondex::Species.all[input].monsters pick_monsters(monsters) else invalid_selection pick_monsters_through_species end end |
#print_details(monster) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mondex/cli.rb', line 40 def print_details(monster) puts "----------------------------------------------------------------------------" puts monster.name.colorize(:color => :black, :background => :white) puts "Description:".colorize(:blue) puts " #{monster.bio}" puts "Species: ".colorize(:light_blue) + "#{monster.species.name} | " + "Locations: ".colorize(:light_blue) + "#{monster.locations}" puts "Weaknesses:".colorize(:red) monster.weakness.each {|w| puts " #{w}"} if monster.weakness puts "Resistances:".colorize(:green) monster.resistances.each {|r| puts " #{r}"} if monster.resistances puts "Elements:".colorize(:yellow) puts " #{monster.elements}" puts "----------------------------------------------------------------------------" end |
#print_list(array_of_monsters) ⇒ Object
59 60 61 |
# File 'lib/mondex/cli.rb', line 59 def print_list(array_of_monsters) array_of_monsters.each_with_index {|m, i| puts "#{i+1}. #{m.name}"} end |
#print_monsters_details(array_of_monsters) ⇒ Object
55 56 57 |
# File 'lib/mondex/cli.rb', line 55 def print_monsters_details(array_of_monsters) array_of_monsters.each {|m| print_details(m)} end |