Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding coursera XML output for fill in blanks

  • Loading branch information...
commit 23504cc7228f909c6ca0dd5810b0fa1f0b895368 1 parent 514332d
@jeady jeady authored
Showing with 64 additions and 7 deletions.
  1. +21 −7 example.rb
  2. +43 −0 lib/xml_renderer.rb
View
28 example.rb
@@ -16,22 +16,36 @@
# - a "blank" is three or more hyphens in a row
# - all regexps are case-INSENSITIVE unless :case_sensitive => true is passed
# - order matters unless :order => false is passed
+ #
+ # Some restrictions that Coursera places on fill in blank questions right now:
+ # - Only a single blank is allowed
+ # - Correct answers should be included in a single regex and merged by using |
fill_in :points => 2 do
text 'The capital of California is ---'
answer 'sacramento'
end
- # multiple blanks, order matters: answer must be an array
+ # short answer fill in blanks question with an explanation
+ # for an incorrect answer
fill_in do
- text 'The --- brown fox jumped over the lazy ---'
- answer [/fox/, /dog/], :explanation => 'This sentence contains all of the letters of the English Alphabet'
+ text 'The visionary founder of Apple is ---'
+ answer /^ste(ve|phen)\s+jobs$/, :explanation => 'Got it!'
+ distractor /^steve\s+wozniak/, :explanation => 'Almost, but not quite.'
end
+ # multiple blanks, order matters: answer must be an array
+ # NOTE: unsupported by Coursera at this time.
+ #fill_in do
+ # text 'The --- brown fox jumped over the lazy ---'
+ # answer [/fox/, /dog/], :explanation => 'This sentence contains all of the letters of the English Alphabet'
+ #end
+
# multiple blanks, order doesn't matter but no answer can be reused
- fill_in :order => false do
- text 'Two of the Three Stooges are --- and ---'
- answer %w(moe larry curly)
- end
+ # NOTE: unsupported by Coursera at this time.
+ #fill_in :order => false do
+ # text 'Two of the Three Stooges are --- and ---'
+ # answer %w(moe larry curly)
+ #end
# true/false questions - explanation is optional
truefalse true, 'The week has 7 days.'
View
43 lib/xml_renderer.rb
@@ -11,6 +11,7 @@ def initialize(quiz,options={})
def render(thing)
case thing
when MultipleChoice,SelectMultiple,TrueFalse then render_multiple_choice(thing)
+ when FillIn then render_fill_in(thing)
else
raise "Unknown question type: #{thing}"
end
@@ -32,6 +33,48 @@ def render_quiz
@output
end
+ def render_fill_in(question)
+ @b.question :type => 'GS_Short_Answer_Question_Simple', :id => question.object_id.to_s(16) do
+ @b.metadata {
+ @b.parameters {
+ @b.rescale_score question.points
+ @b.type 'regexp'
+ }
+ }
+ # since we want all the options to appear, we create N option
+ # groups each containig 1 option, and specify that option to
+ # always be selected for inclusion in the quiz. If the original
+ # question specified 'random', use the 'randomize' attribute on
+ # option_groups to scramble the order in which displayed;
+ # otherwise, display in same order as answers appear in source.
+ @b.data {
+ @b.text { @b.cdata!(question.question_text) }
+ @b.option_groups(:randomize => !!question.randomize) {
+ @b.option_group(:select => 'all') {
+ question.answers.each do |answer|
+ option_args = {}
+ option_args['selected_score'] = answer.correct? ? 1 : 0
+ option_args['unselected_score'] =
+ question.multiple ? 1 - option_args['selected_score'] : 0
+ option_args['id'] = answer.object_id.to_s(16)
+ @b.option(option_args) do
+ answer_text = answer.answer_text
+ if answer_text.kind_of?(Regexp)
+ answer_text = answer_text.inspect
+ if !question.case_sensitive
+ answer_text += 'i'
+ end
+ end
+ @b.text { @b.cdata!(answer_text) }
+ @b.explanation { @b.cdata!(answer.explanation) } if answer.has_explanation?
+ end
+ end
+ }
+ }
+ }
+ end
+ end
+
def render_multiple_choice(question)
@b.question :type => 'GS_Choice_Answer_Question', :id => question.object_id.to_s(16) do
@b.metadata {
Please sign in to comment.
Something went wrong with that request. Please try again.