Class: Moodle2CC::CanvasCC::Models::Assessment
- Inherits:
-
Object
- Object
- Moodle2CC::CanvasCC::Models::Assessment
- Defined in:
- lib/moodle2cc/canvas_cc/models/assessment.rb
Constant Summary collapse
- META_ATTRIBUTES =
[:title, :description, :allowed_attempts, :scoring_policy, :access_code, :ip_filter, :shuffle_answers, :time_limit, :quiz_type]
- DATETIME_ATTRIBUTES =
[:lock_at, :unlock_at]
- ASSESSMENT_TYPE =
'imsqti_xmlv1p2/imscc_xmlv1p1/assessment'
- LAR_TYPE =
'associatedcontent/imscc_xmlv1p1/learning-application-resource'
- ASSESSMENT_NON_CC_FOLDER =
'non_cc_assessments'
Instance Method Summary collapse
- #canvas_assessment_resource ⇒ Object
- #cc_assessment_resource ⇒ Object
-
#initialize ⇒ Assessment
constructor
A new instance of Assessment.
- #meta_file_path ⇒ Object
- #qti_file_path ⇒ Object
- #resolve_question_references!(question_banks) ⇒ Object
- #resources ⇒ Object
Constructor Details
#initialize ⇒ Assessment
Returns a new instance of Assessment.
13 14 15 |
# File 'lib/moodle2cc/canvas_cc/models/assessment.rb', line 13 def initialize @question_references = [] end |
Instance Method Details
#canvas_assessment_resource ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/moodle2cc/canvas_cc/models/assessment.rb', line 30 def canvas_assessment_resource resource = Moodle2CC::CanvasCC::Models::Resource.new resource.identifier = "#{@identifier}_meta" resource.href = resource.type = LAR_TYPE resource.files = [, qti_file_path] resource end |
#cc_assessment_resource ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/moodle2cc/canvas_cc/models/assessment.rb', line 21 def cc_assessment_resource resource = Moodle2CC::CanvasCC::Models::Resource.new resource.identifier = @identifier resource.type = ASSESSMENT_TYPE resource.dependencies = ["#{@identifier}_meta"] resource.files = [] # TODO: export cc qti file resource end |
#meta_file_path ⇒ Object
39 40 41 |
# File 'lib/moodle2cc/canvas_cc/models/assessment.rb', line 39 def "#{@identifier}/assessment_meta.xml" end |
#qti_file_path ⇒ Object
43 44 45 |
# File 'lib/moodle2cc/canvas_cc/models/assessment.rb', line 43 def qti_file_path "#{ASSESSMENT_NON_CC_FOLDER}/#{@identifier}.xml.qti" end |
#resolve_question_references!(question_banks) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/moodle2cc/canvas_cc/models/assessment.rb', line 47 def resolve_question_references!(question_banks) @items ||= [] # keep track of each time a bank is referenced through a random question reference random_bank_counts = {} @question_references.each do |ref| question = nil group = nil question_banks.each do |bank| break if (question = bank.questions.detect{|q| q.original_identifier.to_s == ref[:question]}) || (group = bank.question_groups.detect{|g| g.identifier.to_s == ref[:question]}) if bank.random_question_references.any?{|r| r.to_s == ref[:question]} random_bank_counts[bank] ||= 0 random_bank_counts[bank] += 1 break end end if question question.assessment_question_identifierref ||= "question_#{question.identifier}" copy = question.dup copy.identifier = "#{copy.identifier}_copy" copy.points_possible = ref[:grade] if ref[:grade] @items << copy elsif group copy = group.dup if ref[:grade] && copy.selection_number.to_i != 0 copy.points_per_item = ref[:grade].to_f / copy.selection_number.to_i end @items << copy end end random_bank_counts.each do |bank, count| new_group = Moodle2CC::CanvasCC::Models::QuestionGroup.new new_group.identifier = "#{@identifier}#{bank.identifier}_random_group" new_group.selection_number = count new_group.questions = bank.questions.map(&:dup) child_banks = bank.find_children_banks(question_banks) child_banks.each do |child| new_group.questions += child.questions.map(&:dup) end @items << new_group end @items.select{|i| i.is_a?(Moodle2CC::CanvasCC::Models::QuestionGroup)}.each do |group| group.questions.each do |q| @items.delete_if{|i| i.respond_to?(:original_identifier) && i.original_identifier == q.original_identifier} end end end |
#resources ⇒ Object
17 18 19 |
# File 'lib/moodle2cc/canvas_cc/models/assessment.rb', line 17 def resources [cc_assessment_resource, canvas_assessment_resource] end |