Class: Moodle2CC::Moodle2::Models::Quizzes::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/moodle2cc/moodle2/models/quizzes/question.rb

Constant Summary collapse

STANDARD_TYPES =
%w[description essay random shortanswer].freeze
@@subclasses =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuestion

Returns a new instance of Question.



45
46
47
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 45

def initialize
  @answers = []
end

Instance Attribute Details

#answersObject

Returns the value of attribute answers.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def answers
  @answers
end

#bank_entry_idObject

Returns the value of attribute bank_entry_id.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def bank_entry_id
  @bank_entry_id
end

#default_markObject

Returns the value of attribute default_mark.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def default_mark
  @default_mark
end

#general_feedbackObject

Returns the value of attribute general_feedback.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def general_feedback
  @general_feedback
end

#hiddenObject

Returns the value of attribute hidden.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def hidden
  @hidden
end

#idObject

Returns the value of attribute id.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def id
  @id
end

#lengthObject

Returns the value of attribute length.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def length
  @length
end

#max_markObject

Returns the value of attribute max_mark.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def max_mark
  @max_mark
end

#nameObject

Returns the value of attribute name.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def name
  @name
end

#parentObject

Returns the value of attribute parent.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def parent
  @parent
end

#penaltyObject

Returns the value of attribute penalty.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def penalty
  @penalty
end

#qtypeObject

Returns the value of attribute qtype.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def qtype
  @qtype
end

#question_textObject

Returns the value of attribute question_text.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def question_text
  @question_text
end

#question_text_formatObject

Returns the value of attribute question_text_format.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def question_text_format
  @question_text_format
end

#stampObject

Returns the value of attribute stamp.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def stamp
  @stamp
end

#typeObject

Returns the value of attribute type.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def type
  @type
end

#versionObject

Returns the value of attribute version.



27
28
29
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 27

def version
  @version
end

Class Method Details

.create(type) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 9

def self.create(type)
  if (c = @@subclasses[type])
    q = c.new
    q.type = type
    q
  elsif STANDARD_TYPES.include?(type)
    q = new
    q.type = type
    q
  else
    raise "Unknown question type: #{type}"
  end
end

.register_question_type(name) ⇒ Object



23
24
25
# File 'lib/moodle2cc/moodle2/models/quizzes/question.rb', line 23

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