-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.rb
49 lines (39 loc) · 1.08 KB
/
controller.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
require_relative 'recipe'
require_relative 'view'
require_relative 'parsing'
require_relative 'cookbook'
require 'byebug'
class Controller
attr_accessor :new_recipe, :destroyed_recipe, :imported_recipe, :chosen_recipe, :mark_recipe, :recipe_to_mark
def initialize(cookbook)
@view = View.new
@cookbook = cookbook
end
def list
recipes = @cookbook.recipes
@view.list_recipes(recipes)
end
def create
recipe_name = @view.ask_for_recipe_name
description = @view.ask_for_description
new_recipe = Recipe.new(recipe_name, description)
@cookbook.add_recipe(new_recipe)
end
def destroy
destroyed_recipe = @view.remove_recipe
@cookbook.remove_recipe(destroyed_recipe)
end
def import
recipe_for_parsing = @view.ask_for_ingredient
@parsing = Parsing.new(recipe_for_parsing)
parsed_recipes = @parsing.call
@view.list_recipes(parsed_recipes)
index = @view.choose_recipe
@cookbook.add_recipe(parsed_recipes[index])
end
def mark
list
recipe_to_mark = @view.choose_recipe
@cookbook.mark_recipe(recipe_to_mark)
end
end