Class: Moodle2CC::CanvasCC::Models::QuestionBank

Inherits:
Object
  • Object
show all
Defined in:
lib/moodle2cc/canvas_cc/models/question_bank.rb

Constant Summary collapse

LAR_TYPE =
'associatedcontent/imscc_xmlv1p1/learning-application-resource'
ASSESSMENT_NON_CC_FOLDER =
'non_cc_assessments'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuestionBank

Returns a new instance of QuestionBank.



6
7
8
9
10
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 6

def initialize
  @questions = []
  @question_groups = []
  @random_question_references = []
end

Instance Attribute Details

#identifierObject

Returns the value of attribute identifier.



4
5
6
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 4

def identifier
  @identifier
end

#original_idObject

Returns the value of attribute original_id.



4
5
6
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 4

def original_id
  @original_id
end

#parent_idObject

Returns the value of attribute parent_id.



4
5
6
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 4

def parent_id
  @parent_id
end

#question_groupsObject

Returns the value of attribute question_groups.



4
5
6
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 4

def question_groups
  @question_groups
end

#questionsObject

Returns the value of attribute questions.



4
5
6
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 4

def questions
  @questions
end

#random_question_referencesObject

Returns the value of attribute random_question_references.



4
5
6
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 4

def random_question_references
  @random_question_references
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 4

def title
  @title
end

Instance Method Details

#find_children_banks(all_banks, visited_banks = []) ⇒ Object

recursively find all banks that belong to this one



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 29

def find_children_banks(all_banks, visited_banks=[])
  visited_banks << self
  children = []
  sub_children = []
  all_banks.each do |bank|
    children << bank if bank.parent_id && bank.parent_id == self.original_id && !visited_banks.include?(bank)
  end
  children.each do |child|
    sub_children += child.find_children_banks(all_banks, visited_banks)
  end
  return children + sub_children
end

#question_bank_resourceObject



19
20
21
22
23
24
25
26
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 19

def question_bank_resource
  resource = Moodle2CC::CanvasCC::Models::Resource.new
  resource.identifier = @identifier
  resource.href = "#{ASSESSMENT_NON_CC_FOLDER}/#{resource.identifier}.xml.qti"
  resource.type = LAR_TYPE
  resource.files = [resource.href]
  resource
end

#resourcesObject



15
16
17
# File 'lib/moodle2cc/canvas_cc/models/question_bank.rb', line 15

def resources
  [question_bank_resource]
end