Class: SeaLife::CLI
- Inherits:
-
Object
- Object
- SeaLife::CLI
- Defined in:
- lib/sea_life/cli.rb
Instance Method Summary collapse
- #animal_menu(animal) ⇒ Object
- #call ⇒ Object
- #category_menu(animals) ⇒ Object
- #goodbye ⇒ Object
- #list_animals(category) ⇒ Object
- #list_categories ⇒ Object
- #main_menu(categories) ⇒ Object
- #make_animals_from_category(category) ⇒ Object
- #make_categories ⇒ Object
- #show_animal(animal) ⇒ Object
Instance Method Details
#animal_menu(animal) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sea_life/cli.rb', line 88 def (animal) input = gets.strip.downcase if input == "more" puts "" puts "#{animal.longer_desc}" puts "" puts "Please enter BACK, MENU, or EXIT." (animal) elsif input == "back" list_animals(animal.category) elsif input == "menu" list_categories elsif input == "exit" goodbye else puts "Invalid input. Please enter MORE, BACK, MENU, or EXIT." (animal) end end |
#call ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sea_life/cli.rb', line 3 def call puts "------------------------------------------------------------" puts "" puts " _________ .____ .__ _____" puts " / _____/ ____ _____ | | |__|/ ____\\____" puts " \\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\" puts " / \\ ___/ / __ \\| |___| || | \\ ___/" puts " /_________/\\____/ _____/ ________\\__||__| \\____/" puts "" puts "" puts "------------------------------------------------------------" puts "" puts "Welcome!" list_categories end |
#category_menu(animals) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/sea_life/cli.rb', line 125 def (animals) puts "Please enter the number of your selection." puts "You may also enter BACK or EXIT" input = gets.strip if input.to_i > 0 && input.to_i <= animals.size show_animal(animals[input.to_i - 1]) elsif input.downcase == "back" list_categories elsif input.downcase == "exit" goodbye else puts "Invalid input." (animals) end end |
#goodbye ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/sea_life/cli.rb', line 143 def goodbye puts "------------------------------------------------------------" puts "" puts " _________ .____ .__ _____" puts " / _____/ ____ _____ | | |__|/ ____\\____" puts " \\_____ \\_/ __ \\\\__ \\ | | | \\ __\\/ __ \\" puts " / \\ ___/ / __ \\| |___| || | \\ ___/" puts " /_________/\\____/ _____/ ________\\__||__| \\____/" puts " See you soon!" puts "" puts "------------------------------------------------------------" end |
#list_animals(category) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sea_life/cli.rb', line 42 def list_animals(category) puts "Loading animals..." puts "" make_animals_from_category(category) if category.animals.size == 0 puts "Please select the animal you'd like to learn about:" animals = [] category.animals.each_with_index do |animal, i| puts "#{i + 1}. #{animal.name}" animals << animal end puts "" (animals) end |
#list_categories ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sea_life/cli.rb', line 20 def list_categories puts "" puts "Please choose a category to learn about:" puts "" make_categories if SeaLife::Category.all.size == 0 categories = SeaLife::Category.all categories.each_with_index do |category, i| puts "#{i + 1}. #{category.name}" end puts "" (categories) end |
#main_menu(categories) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/sea_life/cli.rb', line 109 def (categories) puts "Please enter the number of a category:" puts "You may also enter \"EXIT\"." input = gets.strip if input.to_i > 0 && input.to_i <= categories.size list_animals(categories[input.to_i - 1]) elsif input.downcase == "exit" goodbye else puts "Invalid input." (categories) end end |
#make_animals_from_category(category) ⇒ Object
62 63 64 |
# File 'lib/sea_life/cli.rb', line 62 def make_animals_from_category(category) SeaLife::Scraper.scrape_animals(category) end |
#make_categories ⇒ Object
36 37 38 39 40 |
# File 'lib/sea_life/cli.rb', line 36 def make_categories SeaLife::Scraper.scrape_categories.each do |category| SeaLife::Category.new(category) end end |
#show_animal(animal) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/sea_life/cli.rb', line 66 def show_animal(animal) SeaLife::Scraper.scrape_animal_info(animal) unless animal.scientific_name puts "" puts "--------------------------------------------------------------" puts "#{animal.name} (#{animal.scientific_name})" puts "" puts "Distribution: #{animal.distribution}" puts "Ecosystem/Habitat: #{animal.habitat}" puts "Feeding Habits: #{animal.habits}" puts "Conservation Status: #{animal.status}" puts "Taxonomy: #{animal.taxonomy}" puts "--------------------------------------------------------------" puts "" puts "#{animal.short_desc}" puts "" puts "Enter \"MORE\" to continue reading about the #{animal.name}." puts "You may also enter \"BACK\", \"MENU\", or \"EXIT\"." (animal) end |