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
|
# File 'lib/cooklang/builders/recipe_builder.rb', line 7
def build_recipe(parsed_steps, metadata)
all_ingredients = []
all_cookware = []
all_timers = []
steps = []
sections = []
parsed_steps.each do |step_data|
all_ingredients.concat(step_data[:ingredients])
all_cookware.concat(step_data[:cookware])
all_timers.concat(step_data[:timers])
step = Step.new(segments: step_data[:segments])
steps << step
if step_data[:section_name]
sections << Section.new(name: step_data[:section_name], steps: [step])
end
end
unique_ingredients = deduplicate_ingredients(all_ingredients)
unique_cookware = deduplicate_cookware(all_cookware)
Recipe.new(
ingredients: unique_ingredients,
cookware: unique_cookware,
timers: all_timers,
steps: steps,
metadata: metadata,
sections: sections
)
end
|