class SeaLife::CLI

Public Instance Methods

animal_menu(animal) click to toggle source
# File lib/sea_life/cli.rb, line 88
def animal_menu(animal)
  input = gets.strip.downcase

  if input == "more"
    puts ""
    puts "#{animal.longer_desc}"
    puts ""
    puts "Please enter BACK, MENU, or EXIT."
    animal_menu(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_menu(animal)
  end
end
call() click to toggle source
# 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) click to toggle source
# File lib/sea_life/cli.rb, line 125
def category_menu(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."
    category_menu(animals)
  end
end
goodbye() click to toggle source
# 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) click to toggle source
# 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 ""

  category_menu(animals)
end
list_categories() click to toggle source
# 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 ""
  main_menu(categories)
end
main_menu(categories) click to toggle source
make_animals_from_category(category) click to toggle source
# File lib/sea_life/cli.rb, line 62
def make_animals_from_category(category)
  SeaLife::Scraper.scrape_animals(category)
end
make_categories() click to toggle source
# 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) click to toggle source
# 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_menu(animal)
end