Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/menu.rb
Instance Method Summary collapse
-
#account_details ⇒ Object
Cases the account details menu and routes the user.
-
#account_details_select ⇒ Object
Prompts the user to select from the Account details menu.
-
#case_account_details(selection) ⇒ Object
Continues to case the account details menu and route the user.
-
#case_menu(selection) ⇒ Object
Continues to case the menu selection and route the user.
-
#case_my_list(selection, mylist) ⇒ Object
Cases the selection from the MyList menu and routes to the required method.
-
#display_menu ⇒ Object
Prompts the user to select an item on the menu.
-
#initialize(user) ⇒ Menu
constructor
A new instance of Menu.
-
#menu_router ⇒ Object
Begins to case the user selection from the menu.
-
#my_list ⇒ Object
Shows the MyList menu.
-
#no_items ⇒ Object
Sends user back to menu if they don’t have any items in ‘MyList’ yet.
-
#recommendations_menu ⇒ Object
Opens the recommendations menu.
Constructor Details
#initialize(user) ⇒ Menu
Returns a new instance of Menu.
4 5 6 7 8 |
# File 'lib/menu.rb', line 4 def initialize(user) @user = user @prompt = TTY::Prompt.new @playlist = Playlist.new(@user) end |
Instance Method Details
#account_details ⇒ Object
Cases the account details menu and routes the user
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/menu.rb', line 90 def account_details selection = account_details_select case selection when 'View Details' @user.details when 'Change Username' username = @prompt.ask('Please enter your new username >') @user.change_username(username) else case_account_details(selection) end end |
#account_details_select ⇒ Object
Prompts the user to select from the Account details menu
83 84 85 86 87 |
# File 'lib/menu.rb', line 83 def account_details_select system('clear') arr = ['View Details', 'Change Username', 'Change Password', 'Delete Account', 'Back'] @prompt.select('》 ACCOUNT DETAILS 《\n'.colorize(:light_green), arr) end |
#case_account_details(selection) ⇒ Object
Continues to case the account details menu and route the user
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/menu.rb', line 104 def case_account_details(selection) case selection when 'Change Password' password = @prompt.ask('Please enter your new password >') @user.change_password(password) when 'Delete Account' @user.delete_account when 'Back' end end |
#case_menu(selection) ⇒ Object
Continues to case the menu selection and route the user
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/menu.rb', line 49 def (selection) case selection when 'Playlist' @playlist. when 'Account Details' account_details when 'Exit' p "Is this exiting?" end end |
#case_my_list(selection, mylist) ⇒ Object
Cases the selection from the MyList menu and routes to the required method
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/menu.rb', line 69 def case_my_list(selection, mylist) case selection when 'Display' mylist.list when 'Add' mylist.add_to_list when 'Remove' mylist.remove_from_list when 'Back' end end |
#display_menu ⇒ Object
Prompts the user to select an item on the menu
11 12 13 14 15 |
# File 'lib/menu.rb', line 11 def system('clear') arr = ['My List', 'Recommendations', 'Playlist', 'Account Details', 'Exit'] @prompt.select("》 MAIN MENU 《\n".colorize(:light_green), arr) end |
#menu_router ⇒ Object
Begins to case the user selection from the menu
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/menu.rb', line 18 def selection = case selection when 'My List' my_list when 'Recommendations' else (selection) end end |
#my_list ⇒ Object
Shows the MyList menu
61 62 63 64 65 66 |
# File 'lib/menu.rb', line 61 def my_list system('clear') selection = @prompt.select("》 MY LIST 《\n".colorize(:light_green), %w[Display Add Remove Back]) mylist = MyList.new(@user) case_my_list(selection, mylist) end |
#no_items ⇒ Object
Sends user back to menu if they don’t have any items in ‘MyList’ yet
41 42 43 44 45 46 |
# File 'lib/menu.rb', line 41 def no_items puts "Uh oh! You don't have any items in your list yet, so we can't generate any".colorize(:light_red) puts 'recommendations. Please add some before doing this!'.colorize(:light_red) @prompt.keypress('Press any key to return to the previous menu..') end |
#recommendations_menu ⇒ Object
Opens the recommendations menu
31 32 33 34 35 36 37 38 |
# File 'lib/menu.rb', line 31 def if @user.mylist.length.positive? recommendation = Rec.new(@user) recommendation.amount_of_suggestions else no_items end end |