-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.rb
More file actions
67 lines (53 loc) · 1.26 KB
/
Copy pathmenu.rb
File metadata and controls
67 lines (53 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true
require_relative './manager'
require_relative './note'
# menu apllication
class Menu
def initialize
@manager = Manager.new
end
def enter_a_number
index = gets.chomp.to_i
return puts ' Invalid input '.center 50, '*' if index < 1
index
end
def add
print 'Note: '
text = gets.chomp
note = Note.new text
@manager.store note
puts ' Note created '.center 50, '#'
end
def show_all
@manager.show_all
end
def edit
@manager.show_all
print 'Enter Number to Edit: '
index = gets.chomp.to_i
return puts 'Invalid input' if index < 1
edited_note index
end
def edited_note(index)
note = @manager.fetch_note index - 1
return puts ' Invalid input '.center 50, '*' unless note
print 'Note: '
text = gets.chomp.to_s
note.text_note text
@manager.store note
puts ' Entry Updated '.center 50, '*'
end
def delete
@manager.show_all
print 'Enter Number to Delete: '
index = gets.chomp.to_i
return puts 'Invalid input' if index < 1
deleted index
end
def deleted(index)
note = @manager.fetch_note index - 1
return puts 'Invalid input' unless note
@manager.delete note
puts ' Entry Deleted '.center 50, '*'
end
end