Sha256: c5eef8b4602199487ac44fb80ec749297298582d8c859321ffd786232f8b7f9c

Contents?: true

Size: 913 Bytes

Versions: 3

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

module Kitchen::Directions::BakeChapterSolutions
  class V1
    def bake(chapter:, metadata_source:, uuid_prefix: '')
      solutions_clipboard = Kitchen::Clipboard.new

      chapter.search('section.free-response').each do |free_response_question|
        exercises = free_response_question.exercises
        # must run AFTER .free-response notes are baked

        next if exercises.none?

        exercises.each do |exercise|
          solution = exercise.solution
          next unless solution.present?

          solution.cut(to: solutions_clipboard)
        end
      end

      content = solutions_clipboard.paste

      Kitchen::Directions::EocCompositePageContainer.v1(
        container_key: 'solutions',
        uuid_key: "#{uuid_prefix}solutions",
        metadata_source: metadata_source,
        content: content,
        append_to: chapter
      )
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openstax_kitchen-9.2.0 lib/kitchen/directions/bake_chapter_solutions/v1.rb
openstax_kitchen-9.1.0 lib/kitchen/directions/bake_chapter_solutions/v1.rb
openstax_kitchen-9.0.0 lib/kitchen/directions/bake_chapter_solutions/v1.rb