Class: CommonCartridge::Parsers::Questions

Inherits:
Object
  • Object
show all
Defined in:
lib/common_cartridge/parsers/questions.rb

Instance Method Summary collapse

Constructor Details

#initialize(zipfile, quiz) ⇒ Questions

Returns a new instance of Questions.



4
5
6
7
# File 'lib/common_cartridge/parsers/questions.rb', line 4

def initialize(zipfile, quiz)
  @zipfile = zipfile
  @quiz = quiz
end

Instance Method Details

#parse!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/common_cartridge/parsers/questions.rb', line 9

def parse!
  @quiz.file_locations.each do |location|
    Parser.use_file(@zipfile, location) do |xml|
      doc = Nokogiri::XML(xml)
      doc.remove_namespaces!
      unless @quiz.question_count && !canvas?(location)
        # We need all questions that aren't a text only question. Re-usable, important sibling XML elements *sigh*.
        @quiz.question_count = doc.xpath("//item//fieldlabel[text()='question_type' or text()='cc_profile']/following-sibling::fieldentry[1][text() != 'text_only_question']").length
      end

      unless @quiz.points_possible
        if points = doc.xpath("//fieldlabel[text()='points_possible']/following-sibling::fieldentry[1]")
          @quiz.points_possible = points.text
        end
      end
    end
  end
end