Class: Spirit::Render::Processors::ProblemsProcessor

Inherits:
Base
  • Object
show all
Defined in:
lib/spirit/render/processors/problems_processor.rb

Overview

Pre-processes problem markup in YAML. Dependent on renderer#problems and renderer#nesting.

Constant Summary collapse

REGEX =

Paragraphs that start and end with “”“ are treated as embedded YAML and are parsed for questions/answers.

/^"""$(.*?)^"""$/m
MARKER =
/\A<!-- %%(\d+)%% -->\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

events, inherited, #invoke_callbacks_for, process

Constructor Details

#initialize(renderer, *args) ⇒ ProblemsProcessor

Returns a new instance of ProblemsProcessor.



20
21
22
23
24
25
# File 'lib/spirit/render/processors/problems_processor.rb', line 20

def initialize(renderer, *args)
  @renderer  = renderer
  @problems  = []
  @solutions = []
  renderer.problems = self
end

Instance Attribute Details

#problemsObject (readonly)

Returns the value of attribute problems.



15
16
17
# File 'lib/spirit/render/processors/problems_processor.rb', line 15

def problems
  @problems
end

#solutionsObject (readonly)

Returns the value of attribute solutions.



15
16
17
# File 'lib/spirit/render/processors/problems_processor.rb', line 15

def solutions
  @solutions
end

Instance Method Details

#filter(document) ⇒ String

Replaces YAML markup in document with <!– %%index%% –>

Returns:

  • (String)

    document



29
30
31
# File 'lib/spirit/render/processors/problems_processor.rb', line 29

def filter(document)
  document.gsub(REGEX) { problem $1 }
end

#replace(html) ⇒ Object



33
34
35
36
37
# File 'lib/spirit/render/processors/problems_processor.rb', line 33

def replace(html)
  return html unless is_marker? html
  replace_nesting html, renderer.nesting
  ''
end