Class: Moodle2CC::Moodle2Converter::QuestionConverters::QuestionConverter

Inherits:
Object
  • Object
show all
Includes:
ConverterHelper
Defined in:
lib/moodle2cc/moodle2converter/question_converters/question_converter.rb

Constant Summary collapse

STANDARD_CONVERSIONS =
{
  "description" => "text_only_question",
  "essay" => "essay_question",
  "shortanswer" => "short_answer_question"
}.freeze
@@subclasses =
{}

Constants included from ConverterHelper

ConverterHelper::ACTIVITY_LOOKUP, ConverterHelper::ASSESSMENT_SUFFIX, ConverterHelper::ASSIGNMENT_SUFFIX, ConverterHelper::CHAPTER_SUFFIX, ConverterHelper::CHOICE_ASSESSMENT_SUFFIX, ConverterHelper::COURSE_SUFFIX, ConverterHelper::DISCUSSION_SUFFIX, ConverterHelper::EXTERNAL_URL_SUFFIX, ConverterHelper::FEEDBACK_ASSESSMENT_SUFFIX, ConverterHelper::FILE_SUFFIX, ConverterHelper::FOLDER_SUFFIX, ConverterHelper::GLOSSARY_SUFFIX, ConverterHelper::INTRO_SUFFIX, ConverterHelper::LTI_SUFFIX, ConverterHelper::MAX_TITLE_LENGTH, ConverterHelper::MODULE_SUFFIX, ConverterHelper::PAGE_SUFFIX, ConverterHelper::QUESTIONNAIRE_ASSESSMENT_SUFFIX, ConverterHelper::QUESTION_BANK_SUFFIX, ConverterHelper::SUMMARY_PAGE_SUFFIX

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConverterHelper

#activity_content_type, #generate_unique_identifier, #generate_unique_identifier_for, #generate_unique_identifier_for_activity, #generate_unique_resource_path, #get_unique_identifier_for_activity, #truncate_text, #workflow_state

Class Attribute Details

.canvas_question_typeObject

Returns the value of attribute canvas_question_type.



9
10
11
# File 'lib/moodle2cc/moodle2converter/question_converters/question_converter.rb', line 9

def canvas_question_type
  @canvas_question_type
end

Class Method Details

.register_converter_type(name) ⇒ Object



13
14
15
# File 'lib/moodle2cc/moodle2converter/question_converters/question_converter.rb', line 13

def self.register_converter_type(name)
  @@subclasses[name] = self
end

Instance Method Details

#convert(moodle_question) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/moodle2cc/moodle2converter/question_converters/question_converter.rb', line 23

def convert(moodle_question)
  type = moodle_question.type
  if type && (c = @@subclasses[type])
    c.new.convert_question(moodle_question)
  elsif type && (question_type = STANDARD_CONVERSIONS[type])
    convert_question(moodle_question, question_type)
  else
    raise "Unknown converter type: #{type}"
  end
end

#convert_question(moodle_question, question_type = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/moodle2cc/moodle2converter/question_converters/question_converter.rb', line 34

def convert_question(moodle_question, question_type = nil)
  canvas_question = create_canvas_question(question_type, moodle_question)
  canvas_question.identifier = generate_unique_identifier_for(moodle_question.id, "_quiz_question")
  canvas_question.original_identifier = moodle_question.id
  canvas_question.bank_entry_id = moodle_question.bank_entry_id
  canvas_question.title = truncate_text(moodle_question.name)
  canvas_question.points_possible = moodle_question.max_mark
  canvas_question.general_feedback = moodle_question.general_feedback
  canvas_question.answers = moodle_question.answers.map do |moodle_answer|
    Moodle2CC::CanvasCC::Models::Answer.new(moodle_answer)
  end
  canvas_question.material = convert_question_text(moodle_question)
  canvas_question
end

#convert_question_text(moodle_question) ⇒ Object



49
50
51
52
53
# File 'lib/moodle2cc/moodle2converter/question_converters/question_converter.rb', line 49

def convert_question_text(moodle_question)
  material = moodle_question.question_text || ""
  material = RDiscount.new(material).to_html if moodle_question.question_text_format.to_i == 4 # markdown
  material
end

#create_canvas_question(question_type = nil, question = nil) ⇒ Object



55
56
57
58
59
60
# File 'lib/moodle2cc/moodle2converter/question_converters/question_converter.rb', line 55

def create_canvas_question(question_type = nil, question = nil)
  question_type ||= self.class.canvas_question_type
  raise "set canvas_question_type in question converter subclasses" unless question_type

  Moodle2CC::CanvasCC::Models::Question.create(question_type)
end