Class: Cooklang::Builders::RecipeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cooklang/builders/recipe_builder.rb

Class Method Summary collapse

Class Method Details

.build_recipe(parsed_steps, metadata) ⇒ Object



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, )
  # Aggregate all elements from steps
  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

    # Create section if this step has a section name
    if step_data[:section_name]
      sections << Section.new(name: step_data[:section_name], steps: [step])
    end
  end

  # Deduplicate ingredients and cookware
  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: ,
    sections: sections
  )
end