class Shark::CLI

Public Instance Methods

call() click to toggle source
# File lib/shark/shark_cli.rb, line 3
def call 
    puts ""
    puts "Welcome to Oceana's Sharks and Rays Encyclopedia!"
    puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    Shark::Scraper.new.make_sharks
    start
end
list_sharks() click to toggle source
# File lib/shark/shark_cli.rb, line 68
def list_sharks
    Shark::SharkRays.all.each.with_index(1) do |shark, index|
        puts "#{index}. #{shark.name}"
    end
end
print_shark(shark) click to toggle source
start() click to toggle source
# File lib/shark/shark_cli.rb, line 11
def start 
    puts ""
    puts "Which shark or ray would you like to learn more about?"
    list_sharks
    puts ""
    puts "Type 'exit' if you wish to exit the program, otherwise please select a number."

    input = gets.strip

    if input == 'exit'
        return
    end

    if valid_number?(input, Shark::SharkRays.all) == false
        puts ""
        puts "The sharks don't understand that answer, please input a valid number."
        start
    else
        shark = Shark::SharkRays.find(input.to_i)

        print_shark(shark)

        puts ""
        puts "Would you like to learn about another shark or ray? Enter Y or N."

        input = gets.strip.downcase
        if input == "y"
            start
          elsif input == "n"
            puts ""
            puts "Thank you! Come back soon to learn more!"
            exit
          else
            puts ""
            puts "The sharks don't understand that answer."
            start
        end 
    end
end
valid_number?(input, data) click to toggle source
# File lib/shark/shark_cli.rb, line 74
def valid_number?(input, data)
    input.to_i <= data.length && input.to_i > 0 
end