class CLI

Public Instance Methods

another_house_info() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 75
def another_house_info
    puts "Would you like information on another house? Enter 'Yes' or 'No'."
    input = gets.chomp
    if input == 'Yes'
        get_another_house_input
    elsif input == 'No'
        sleep 1
        normal_exit
    else
        sleep 1
        error
        another_house_info
    end
end
early_exit() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 104
def early_exit
    puts "We'll miss you this term. Enjoy your ride on the Hogwarts Express!"
    exit
end
error() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 114
def error
    puts "Sorry, we don't understand that muggle phrase."
    sleep 2
end
get_another_house_input() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 90
def get_another_house_input
    puts "Please choose a house: Gryffindor, Hufflepuff, Ravenclaw, or Slytherin."
    input = gets.chomp
    if input == "Gryffindor" || input == "Hufflepuff" || input == "Ravenclaw" || input == "Slytherin"
        house = House.all.find{|house| house.name == input}
        print_house_info(house)
    else
        sleep 1
        error
        get_another_house_input
    end
    another_house_info
end
main() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 8
def main
    puts "Welcome to Hogwarts, first-year!" 
    sleep 1
    puts "To proceed to the Great Hall for the Sorting Ceremony, enter 'Let's go!'"
    sleep 1
    puts "To leave Hogwarts, enter 'Take me home!'"

    input = gets.chomp

    if input == "Let's go!"
        sleep 1
        sort
    elsif input == "Take me home!"
        sleep 1
        early_exit
    else
        sleep 1
        error
        main
    end
end
more_house_info() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 43
def more_house_info
    puts "Would you like more information on your house? Enter 'Yes' or 'No'."
    input = gets.chomp
    if input == 'Yes'
        print_house_info(@@sorted_house)
        another_house_info
    elsif input == 'No'
        sleep 1
        another_house_info
    else
        sleep 1
        error
        more_house_info
    end
end
normal_exit() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 109
def normal_exit
    puts "Have a great term, #{@@sorted_house.name}!"
    exit
end
print_house_info(house) click to toggle source
run() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 3
def run
    API.get_houses
    main
end
sort() click to toggle source
# File lib/hogwarts_cli/cli.rb, line 30
def sort
    @@sorted_house = House.all.sample
    print "You're in" 
    sleep 1 
    3.times do 
        print "." 
        sleep 1 
    end
    print "#{@@sorted_house.name}!" "\n"
    sleep 2
    more_house_info
end