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
68
69
70
71
72
|
# File 'lib/budget_bytes_cli/cli.rb', line 3
def call
puts "Welcome to Budget Bytes CLI!"
BudgetBytesCli::Scraper.create_categories
category_selector = BudgetBytesCli::ArrayPrompter.new("Selecting recipe category.")
category_selector.array_to_select = BudgetBytesCli::Category.all.map {|i| i.name}
recipe_selector = BudgetBytesCli::ArrayPrompter.new("Selecting recipe")
cat_combination_selector = BudgetBytesCli::ArrayPrompter.new("Selecting category to combine.")
current_selector = category_selector
selection = category_selector.get_input
selected_category = nil
filtered_categories = []
recipe_array = []
while selection != 'Q'
if current_selector == category_selector
selected_category = BudgetBytesCli::Category.all[selection.to_i - 1]
whether_to_combine = yes_no_input("Combine with another category?\nIn other words, display only recipes in both the current category and another you select?\n")
if whether_to_combine == 'Y'
current_selector = cat_combination_selector
filtered_categories = BudgetBytesCli::Category.all.select do |c|
c != selected_category
end
cat_combination_selector.array_to_select = filtered_categories.map {|i| i.name}
else
current_selector = recipe_selector
recipe_array = selected_category.recipes
recipe_selector.array_to_select = selected_category.recipes.map {|i| i.name}
end
elsif current_selector == cat_combination_selector
combination_category = filtered_categories[selection.to_i - 1]
recipe_array = selected_category.combine_recipes(combination_category)
if recipe_array.empty?
valid_input_empty_array = false
while !valid_input_empty_array
puts "No recipes are in the two categories to combine."
puts "Enter 'B' to select a different category to combine,"
puts "'C' to start fresh with a different recipe category,"
puts "or 'I' to ignore the recipe combination and use the category you chose."
empty_array_input = gets.strip.upcase
if empty_array_input == 'B'
current_selector = cat_combination_selector
valid_input_empty_array = true
elsif empty_array_input == 'C'
valid_input_empty_array = true
current_selector = category_selector
elsif empty_array_input == 'I'
valid_input_empty_array = true
current_selector = recipe_selector
recipe_array = selected_category.recipes
recipe_selector.array_to_select = selected_category.recipes.map {|i| i.name}
end
end
else
current_selector = recipe_selector
recipe_selector.array_to_select = recipe_array.map {|i| i.name}
end
else
selected_recipe = recipe_array[selection.to_i - 1]
self.display_recipe(selected_recipe)
current_selector = category_selector
end
selection = current_selector.get_input
end
end
|