diff --git a/main.rb b/main.rb index c216b21..e065bd0 100644 --- a/main.rb +++ b/main.rb @@ -1,11 +1,22 @@ require_relative 'school_library/app' -require_relative 'school_library/modules/display_menu' def main App.run end +def display_menu + puts "\nPlease choose an option by enter a number:" + puts '1. List all books' + puts '2. List all people' + puts '3. Create a person' + puts '4. Create a book' + puts '5. Create a rental' + puts '6. List all rentals for a given person (by ID)' + puts '7. Exit' + print 'Enter your choice: ' + gets.chomp.to_i +end + def handle_choice(choice) - extend DisplayMenu case choice when 1 list_books diff --git a/school_library/app.rb b/school_library/app.rb index 790dcb7..460c7e7 100644 --- a/school_library/app.rb +++ b/school_library/app.rb @@ -1,20 +1,14 @@ -require_relative 'modules/display_menu' require_relative 'modules/create_persons' require_relative 'modules/create_books' require_relative 'modules/lists' class App - extend DisplayMenu extend CreatePerson extend CreateBook extend Lists def self.run - loop do - display_menu - choice = gets.chomp.to_i - handle_choice(choice) - break if choice == 7 - end + choice = handle_choice(choice) while choice != 7 + puts 'Thanks for using the School Library!' end end diff --git a/school_library/modules/display_menu.rb b/school_library/modules/display_menu.rb deleted file mode 100644 index 604835c..0000000 --- a/school_library/modules/display_menu.rb +++ /dev/null @@ -1,43 +0,0 @@ -module DisplayMenu - def display_menu - puts "\nPlease choose an option by enter a number:" - puts '1. List all books' - puts '2. List all people' - puts '3. Create a person' - puts '4. Create a book' - puts '5. Create a rental' - puts '6. List all rentals for a given person (by ID)' - puts '7. Exit' - print 'Enter your choice: ' - end - - # rubocop:disable Metrics/CyclomaticComplexity - def handle_choice(choice) - case choice - when 1 - list_books - when 2 - list_people - when 3 - create_person - when 4 - create_book - when 5 - create_rental - when 6 - print 'Enter person ID: ' - person_id = gets.chomp.to_i - list_rentals_for_person(person_id) - when 7 - puts 'Thanks you for using this app!' - else - invalid_choice - end - end - - # rubocop:enable Metrics/CyclomaticComplexity - - def invalid_choice - puts 'Invalid choice. Please enter a valid option (1-7).' - end -end