Class: Moodle2CC::Moodle::Mod

Inherits:
Object
  • Object
show all
Includes:
HappyMapper
Defined in:
lib/moodle2cc/moodle/mod.rb

Defined Under Namespace

Classes: Option, Page, QuestionInstance

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#courseObject

Returns the value of attribute course.



5
6
7
# File 'lib/moodle2cc/moodle/mod.rb', line 5

def course
  @course
end

Instance Method Details

#grade_itemObject



94
95
96
# File 'lib/moodle2cc/moodle/mod.rb', line 94

def grade_item
  course.grade_items.find { |grade_item| grade_item.item_instance == id }
end

#questionsObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/moodle2cc/moodle/mod.rb', line 98

def questions
  if mod_type == 'questionnaire'
    @questions.sort! { |a,b| a.position <=> b.position }
    return @questions
  end
  if mod_type == 'choice'
    question = Question.new
    question.id = "choice_question_#{@id}"
    question.name = @name
    question.text = @text
    question.type = @mod_type
    question.grade = 1
    question.answers = []
    @options.each do |option|
      answer = Question::Answer.new
      answer.id = option.id
      answer.text = option.text
      question.answers << answer
    end
    @questions = [question]
  else
    question_instances.reject!{ |qi| qi.question.nil? }
    @questions = question_instances.map do |qi|
      question = qi.question
      question.grade = qi.grade
      question.instance_id = qi.id
      question
    end
  end
end

#section_modObject



90
91
92
# File 'lib/moodle2cc/moodle/mod.rb', line 90

def section_mod
  course.sections.map { |section| section.mods.find { |mod| mod.instance_id == id && mod.mod_type == mod_type } }.compact.first
end