class CommonCartridge::Parsers::Questions

Public Class Methods

new(zipfile, quiz) click to toggle source
# File lib/common_cartridge/parsers/questions.rb, line 4
def initialize(zipfile, quiz)
  @zipfile = zipfile
  @quiz = quiz
end

Public Instance Methods

parse!() click to toggle source
# 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

Private Instance Methods

canvas?(location) click to toggle source
# File lib/common_cartridge/parsers/questions.rb, line 29
def canvas?(location)
  location =~ /non_cc_assessments/
end