-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoviesCRUD.rb
60 lines (52 loc) · 1.55 KB
/
moviesCRUD.rb
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
movies = {
Sayonara: 4,
Oblivion: 3,
Memento: 2
}
loop do
puts "--- What do you want to do with your movies? [add/update/display/delete/exit] ---"
choice=gets.chomp
puts "You selected: " + choice
choice.downcase!
case choice
when "add"
puts "What is the title of the movie?"
title=gets.chomp
if movies[title.to_sym].nil?
puts "What is the rating [1 to 5 stars]?"
rating=gets.chomp
movies[title.to_sym]=rating.to_i
puts "We have added: #{title} with a raiting: #{rating}"
else
puts "you already have this movie in your list"
end
when "update"
puts "Which is the title you want to update?"
title= gets.chomp
if movies[title.to_sym].nil?
puts "We don't have that movie listed"
else
puts "Which is the new rating [1 to 5 stars]?"
rating=gets.chomp
movies[title.to_sym]=rating.to_i;
puts "#{title} has been updated to #{rating}"
end
when "display"
movies.each {|title,rating| puts "#{title}: #{rating}" }
when "delete"
puts "Which title do you like to delete from your existence?"
title=gets.chomp
if movies[title.to_sym].nil?
puts "This is very strange, I don't have it listed"
else
movies.delete(title.to_sym)
title.gsub!(/[aeiou]/, '*')
puts "Did you mean #{title} .. mmm I think I have forgoten already"
end
when "exit"
puts "Thanks for using our services, we hope to see you again soon"
break
else
puts "Error! i'm sorry mister, that is something we can't do"
end
end