Module: QuestionMoodleXMLFormatter

Defined in:
lib/asker/formatter/question_moodlexml_formatter.rb

Overview

Transform Questions into Gift format

Class Method Summary collapse

Class Method Details

.choice_to_s(question) ⇒ 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/asker/formatter/question_moodlexml_formatter.rb', line 18

def self.choice_to_s(question)
  s = []

  penalties = ['', '%-50%', '%-33.33333%', '%-25%', '%-20%']
  penalty = penalties[question.bads.size]

  s << "<!-- question: #{question.name}  -->"
  s << '<question type="multichoice">'
  s << '  <name>'
  s << "    <text>#{question.name}</text>"
  s << '  </name>'
  s << '  <questiontext format="html">'
  s << "    <text><![CDATA[#{question.text}]]></text>"
  s << '  </questiontext>'
  s << '  <generalfeedback format="html">'
  s << "    <text>#{question.feedback}</text>"
  s << '  </generalfeedback>'
  s << '  <defaultgrade>1.0000000</defaultgrade>'
  s << "  <penalty>#{penalty}</penalty>"
  s << '  <hidden>0</hidden>'
  s << '  <single>true</single>'
  s << "  <shuffleanswers>#{question.shuffle?}</shuffleanswers>"
  s << '  <answernumbering>abc</answernumbering>'
  s << '  <incorrectfeedback format="html">'
  s << "    <text>#{question.feedback}</text>"
  s << '  </incorrectfeedback>'
  s << '  <answer fraction="100" format="html">'
  s << "    <text>#{question.good}</text>"
  s << '  </answer>'
  s << '  <answer fraction="-25" format="html">'
  s << "    <text>#{question.bad[0]}</text>"
  s << '  </answer>'
  s << '  </question>'
  s << '  <answer fraction="-25" format="html">'
  s << "    <text>#{question.bad[1]}</text>"
  s << '  </answer>'
  s << '  </question>'
  s << '  <answer fraction="-25" format="html">'
  s << "    <text>#{question.bad[2]}</text>"
  s << '  </answer>'
  s << '  </question>'
  s
end

.sanitize(input = '') ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/asker/formatter/question_moodlexml_formatter.rb', line 62

def self.sanitize(input = '')
  output = input.dup
  output.tr!("\n", " ")
  output.tr!(":", "\:")
  output.tr!("=", "\\=")
  # output.gsub!('{', "\\{")
  # output.gsub!('}', "\\}")
  output
end

.to_s(question) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/asker/formatter/question_moodlexml_formatter.rb', line 5

def self.to_s(question)
  @question = question

  case @question.type
  when :choice
    s += choice_to_s(question)
  when :boolean
  when :match
  when :short
  end
  s.flaten!
end