Class: Ruql::Olx
- Inherits:
-
Object
- Object
- Ruql::Olx
- Defined in:
- lib/ruql/olx/olx.rb,
lib/ruql/olx/version.rb,
lib/ruql/olx/exported_edx_course.rb
Defined Under Namespace
Classes: ExportedEdxCourse
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(quiz, options = {}) ⇒ Olx
constructor
A new instance of Olx.
- #more_in_group?(q) ⇒ Boolean
- #render_answers(q) ⇒ Object
- #render_multiple_choice(q) ⇒ Object
- #render_question_text(q) ⇒ Object
-
#render_questions ⇒ Object
this is what’s called when the OLX template yields:.
- #render_quiz ⇒ Object
- #render_select_multiple(q) ⇒ Object
- #time_limit ⇒ Object
Constructor Details
#initialize(quiz, options = {}) ⇒ Olx
Returns a new instance of Olx.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruql/olx/olx.rb', line 8 def initialize(quiz,={}) @quiz = quiz @dryrun = !! .delete('--dry-run') if (chapter = .delete('--chapter')) root = .delete('--root') || Dir.getwd @edx = Ruql::Olx::ExportedEdxCourse.new(quiz, chapter, root, # quiz options for edX { is_time_limited: "true", default_time_limit_minutes: self.time_limit, display_name: quiz.title, exam_review_rules: "", is_onboarding_exam: "false", is_practice_exam: "false", is_proctored_enabled: "false" }, dryrun: @dryrun) end @question_number = 1 @groupselect = (.delete('--group-select') || 1_000_000).to_i @output = '' @h = nil # XML Builder object end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/ruql/olx/olx.rb', line 6 def output @output end |
Class Method Details
.allowed_options ⇒ Object
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 |
# File 'lib/ruql/olx/olx.rb', line 32 def self. opts = [ ['--chapter', GetoptLong::REQUIRED_ARGUMENT], ['--root', GetoptLong::REQUIRED_ARGUMENT], ['--group-select', GetoptLong::REQUIRED_ARGUMENT], ['--dry-run', GetoptLong::NO_ARGUMENT] ] help = <<eos The OLX renderer modifies an exported edX course tree in place to incorporate the quiz. It supports these options: --chapter '<name>' Insert the quiz as the last child (sequential) of the chapter whose display name is <name>. Use quotes as needed to protect spaces/special characters in chapter name. If multiple chapter names match, the quiz will end up in one of them. If this option is omitted, the problem XML will instead be written to standard output, and no files will be created or modified. --root=<path> Specify <path> as root directory of the edX course export. If omitted, default is '.' --dry-run Only valid with --chapter: report names of created files but then delete them from export. The files are created and deleted, so not a true dry run, but leaves the export intact while verifying that the changes are possible. --group-select=<n> If multiple RuQL questions share the same 'group' attribute, include at most n of them in the output. If omitted, defaults to "all questions in group". eos return [help, opts] end |
Instance Method Details
#more_in_group?(q) ⇒ Boolean
105 106 107 108 109 110 111 |
# File 'lib/ruql/olx/olx.rb', line 105 def more_in_group?(q) group = q.question_group # OK to proceed if q. has no group, OR if we haven't used @groupselect questions in group return true if group.to_s == '' @groups_seen[group] += 1 return (@groups_seen[group] <= @groupselect) end |
#render_answers(q) ⇒ Object
135 136 137 138 139 |
# File 'lib/ruql/olx/olx.rb', line 135 def render_answers(q) q.answers.each do |answer| @h.choice(correct: answer.correct?) { |l| l << answer.answer_text } end end |
#render_multiple_choice(q) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ruql/olx/olx.rb', line 113 def render_multiple_choice(q) @h.problem(display_name: "Question #{@question_number}", markdown: 'null') do @h.multiplechoiceresponse do render_question_text(q) @h.choicegroup(type: 'MultipleChoice') do render_answers(q) end end end end |
#render_question_text(q) ⇒ Object
141 142 143 144 145 |
# File 'lib/ruql/olx/olx.rb', line 141 def render_question_text(q) qtext = q.question_text qtext << " Select ALL that apply." if q.multiple @h.label { |l| l << qtext } end |
#render_questions ⇒ Object
this is what’s called when the OLX template yields:
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ruql/olx/olx.rb', line 83 def render_questions @quiz.questions.each do |q| question_xml = '' @h = Builder::XmlMarkup.new(:target => question_xml, :indent => 2) # have we maxed out the number of questions per group for this group? next unless more_in_group?(q) case q when MultipleChoice then render_multiple_choice(q) when SelectMultiple then render_select_multiple(q) else raise Ruql::QuizContentError.new "Unknown question type: #{q}" end # question_xml now contains the XML of the given question... if @edx @edx.add_problem(question_xml) else @output << question_xml << "\n" end @question_number += 1 end end |
#render_quiz ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruql/olx/olx.rb', line 61 def render_quiz # caller expects to find "quiz content" in @output, but if we modified edX, then # output is just the report of what we did. @groups_seen = Hash.new { 0 } @group_count = 0 render_questions if @edx @edx.add_quiz @output = @edx.report end end |
#render_select_multiple(q) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ruql/olx/olx.rb', line 124 def render_select_multiple(q) @h.problem(display_name: "Question #{@question_number}", markdown: 'null') do @h.choiceresponse do render_question_text(q) @h.checkboxgroup do render_answers(q) end end end end |
#time_limit ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/ruql/olx/olx.rb', line 73 def time_limit minutes_per_point = 1 slop = 5 # extra time for setup, etc limit = @quiz.points.to_i * minutes_per_point + slop # round up to next 5 minutes limit += 5 - (limit % 5) limit end |