Class: Asciidoctor::Question::QuestionBlockProcessor

Inherits:
Extensions::BaseProcessor show all
Defined in:
lib/asciidoctor-question/question/extension.rb

Instance Method Summary collapse

Methods inherited from Extensions::BaseProcessor

inherited, #post_answers, #process_error, #process_error_push

Constructor Details

#initialize(name = nil, config = {}) ⇒ QuestionBlockProcessor



13
14
15
16
# File 'lib/asciidoctor-question/question/extension.rb', line 13

def initialize name = nil, config = {}
  super name, config
  @@id = 0
end

Instance Method Details

#has_solution(parent) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/asciidoctor-question/question/extension.rb', line 45

def has_solution(parent)
  if not ( parent.document.attributes['solution'].nil? and parent.attributes['solution'].nil? )
    true
  else
    if parent.parent.nil?
      false
    else
      has_solution(parent.parent)
    end
  end
end

#process(parent, source, tag) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/asciidoctor-question/question/extension.rb', line 18

def process(parent, source, tag)
  block = nil
  err = nil

  type = tag[:type]
  type = tag[:type] = 'mc' if type == 'mc' or type == 'multiplechoice' or type == 'multiple_choice'
  tag[:id] = @@id = @@id + 1

  tag[:solution] = has_solution parent

  if type.nil?
    err = 'Typ fehlt.'
  end

  if err.nil?
    if type == 'mc'
      block = process_question_mc parent, source, tag
    elsif type == 'gap'
      block = process_question_gap parent, source, tag
    end
  else
    block = process_error parent, err, source.lines
  end

  block
end