Sha256: c3892d4eecdbfec82fb36878fddadcd0081ea22f51f52f0791f029731774e23b
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
# frozen_string_literal: true module Kitchen::Directions::BakeChapterAnswerKey module Strategies class UPhysics def bake(chapter:, append_to:) bake_from_notes(chapter: chapter, append_to: append_to, klass: 'check-understanding') classes = %w[review-conceptual-questions review-problems review-additional-problems review-challenge] classes.each do |klass| bake_section(chapter: chapter, append_to: append_to, klass: klass) end end protected def bake_section(chapter:, append_to:, klass:) section_solutions_set = [] chapter.search(".#{klass}").each do |section| section.search('[data-type="solution"]').each do |solution| section_solutions_set.push(solution.cut) end end return if section_solutions_set.empty? title = I18n.t(:"eoc.#{klass}") append_solution_area(title, section_solutions_set, append_to) end def bake_from_notes(chapter:, append_to:, klass:) solutions = [] chapter.notes(".#{klass}").each do |note| solution = note.exercises.first.solution solutions.push(solution.cut) if solution end return if solutions.empty? title = I18n.t(:"notes.#{klass}") append_solution_area(title, solutions, append_to) end def append_solution_area(title, solutions, append_to) append_to = append_to.add_child( <<~HTML <div class="os-solution-area"> <h3 data-type="title"> <span class="os-title-label">#{title}</span> </h3> </div> HTML ).first solutions.each do |solution| append_to.add_child(solution.raw) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
openstax_kitchen-3.2.0 | lib/kitchen/directions/bake_chapter_answer_key/strategies/uphysics.rb |
openstax_kitchen-3.1.0 | lib/kitchen/directions/bake_chapter_answer_key/strategies/uphysics.rb |