Class: Kitchen::Directions::MoveSolutionsFromNumberedNote::V2

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_numbered_note.rb

Instance Method Summary collapse

Instance Method Details

#bake(chapter:, append_to:, note_class:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_numbered_note.rb', line 33

def bake(chapter:, append_to:, note_class:)
  return unless chapter.notes("$.#{note_class}").solutions.any?

  notes_title = <<~HTML
    <h3 data-type="title">
      <span class="os-title-label">#{I18n.t(:"notes.#{note_class}")}</span>
    </h3>
  HTML
  append_to.append(child: notes_title)

  solutions_clipboard = Kitchen::Clipboard.new

  # group multiple solutions per exercise
  chapter.notes("$.#{note_class}").each do |note|
    number = "#{chapter.count_in(:book)}.#{note.count_in(:chapter)}"
    solutions_clipboard = note.solutions&.cut

    title = <<~HTML
      <span class="os-note-number">#{number}</span>
    HTML

    append_to.append(child:
      Kitchen::Directions::SolutionAreaSnippet.v1(
        title: title, solutions_clipboard: solutions_clipboard
      )
    )

    solutions_clipboard.clear
  end
end