Class: Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/menu.rb

Instance Method Summary collapse

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_detailsObject

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 
  selection = 
  case selection
  when 'View Details'
    @user.details
  when 'Change Username'
    username = @prompt.ask('Please enter your new username >')
    @user.change_username(username)
  else
    (selection)
  end
end

#account_details_selectObject

Prompts the user to select from the Account details menu



83
84
85
86
87
# File 'lib/menu.rb', line 83

def 
  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 (selection)
  case selection
  when 'Change Password'
    password = @prompt.ask('Please enter your new password >')
    @user.change_password(password)
  when 'Delete Account'
    @user.
  when 'Back'
    menu_router
  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 case_menu(selection)
  case selection
  when 'Playlist'
    @playlist.menu
  when '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'
    menu_router
  end
end

#display_menuObject

Prompts the user to select an item on the menu



11
12
13
14
15
# File 'lib/menu.rb', line 11

def display_menu
  system('clear')
  arr = ['My List', 'Recommendations', 'Playlist', 'Account Details', 'Exit']
  @prompt.select("》  MAIN MENU  《\n".colorize(:light_green), arr)
end

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 menu_router
  selection = display_menu
  case selection
  when 'My List'
    my_list
  when 'Recommendations'
    recommendations_menu
  else
    case_menu(selection)
  end
end

#my_listObject

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_itemsObject

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..')
  menu_router
end

#recommendations_menuObject

Opens the recommendations menu



31
32
33
34
35
36
37
38
# File 'lib/menu.rb', line 31

def recommendations_menu
  if @user.mylist.length.positive?
    recommendation = Rec.new(@user)
    recommendation.amount_of_suggestions
  else
    no_items
  end
end