Class: Asciidoctor::Question::MultipleChoiceBlockProcessor
Instance Method Summary
collapse
inherited, #post_answers, #process_error, #process_error_push
Instance Method Details
#prepare_answer_lines(lines) ⇒ Object
57
58
59
|
# File 'lib/asciidoctor-question/multiple_choice/extension.rb', line 57
def prepare_answer_lines(lines)
lines
end
|
#prepare_answers(answers_block, tag) ⇒ Object
61
62
63
64
|
# File 'lib/asciidoctor-question/multiple_choice/extension.rb', line 61
def prepare_answers(answers_block, tag)
answers_block.blocks.shuffle! if tag[:shuffle]
answers_block
end
|
#process(parent, source, tag) ⇒ Object
10
11
12
13
14
15
16
17
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
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/asciidoctor-question/multiple_choice/extension.rb', line 10
def process(parent, source, tag)
id = tag[:id]
err = nil
question = Array.new
answers = Array.new ['[options=interactive]']
switch = false
source.lines.each do |line|
switch = true if line =~ /^-\s?\[/
if switch
answers.push line
else
question.push line
end
end
answers = prepare_answer_lines answers
attrs = {'id' => "question_#{id}_type=mc"}
attrs['id'] += '_shuffle' unless tag[:shuffle].nil?
new_parent = Asciidoctor::Block.new parent, :open, {:attributes => attrs}
reader = Asciidoctor::Reader.new(question)
loop do
block = Asciidoctor::Parser.next_block reader, new_parent
break if block.nil?
new_parent.blocks.push block
end
reader = Asciidoctor::Reader.new(answers)
answers_block = Asciidoctor::Parser.next_block reader, new_parent
if answers_block.nil?
err = 'Es sind keine Antworten vorhanden!'
end
if err.nil?
new_parent.blocks.push prepare_answers answers_block, tag
post_answers new_parent, tag
else
process_error_push new_parent, err, answers
end
new_parent
end
|