-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
54 lines (45 loc) · 1.1 KB
/
app.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
def create_grocery_list
print "Enter a name for grocery list: "
list_name = gets.chomp.to_s
return {"name" => list_name, "items" => []}
end
def add_new_item
print "What would you like to add: "
item_name = gets.chomp.to_s
print "How much: "
item_qty = gets.chomp.to_i
return {"name" => item_name, "quantity" => item_qty}
end
def continue?()
print "Add more items (yes|no)? "
answer = gets.chomp.to_s.downcase
if answer == 'yes'
return true
else
return false
end
end
def print_character(character, times)
puts character.to_s * times.to_i
end
def print_list(list)
print_character("-", 75)
list["items"].each do |item|
puts "\tName: \t\t\t#{item['name'].to_s}"
puts "\tQty: \t\t\t#{item['quantity'].to_s}"
end
print_character("-", 75)
end
list = create_grocery_list()
puts "Great! I created #{list['name']} for you. Now add items."
continue_add = true
loop do
new_item = add_new_item()
list["items"].push(new_item)
print "Are you done? (yes | no)"
answer = gets.chomp.to_s.downcase
if answer == 'yes' || answer == 'y'
break
end
end
print_list(list)