Sha256: afc4d4c3d4b01803bfeb2ce6b623dc34fe97151610cdf8ede4122581c320f4c0

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

require_relative "../application"
require_relative "../version"
require_relative "../formatter/question2moodle_xml"

class Export2MoodleXML
  def call(data, project)
    file = File.open(project.get(:moodlepath), "w")
    add_header(file, project)

    export_concepts(concepts: data[:concepts_ai], file: file)
    export_codes(codes: data[:codes_ai], file: file)
    export_problems(problems: data[:problems], file: file)

    close(file)
  end

  private

  def add_header(file, project)
    file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
    file.write("<quiz>\n")
    file.write("<!--\n#{"=" * 50}\n")
    file.write(" #{Asker::NAME}    : version #{Asker::VERSION}\n")
    file.write(" Filename : #{project.get(:moodlename)}\n")
    file.write(" Datetime : #{Time.new}\n")
    file.write("#{"=" * 50}\n-->\n\n")
    file
  end

  def close(file)
    file.write("</quiz>\n")
    file.close
  end

  def export_concepts(concepts:, file:)
    concepts.each do |concept_ai|
      next unless concept_ai.concept.process?

      Application.instance.config["questions"]["stages"].each do |stage|
        concept_ai.questions[stage].each do |question|
          file.write(Question2MoodleXML.new.format(question))
        end
      end
    end
  end

  def export_codes(codes:, file:)
    codes.each do |code|
      next unless code.process?
      code.questions.each do |question|
        file.write Question2MoodleXML.new.format(question)
      end
    end
  end

  def export_problems(problems:, file:)
    problems.each do |problem|
      next unless problem.process?
      problem.questions.each do |question|
        file.write Question2MoodleXML.new.format(question)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
asker-tool-2.9.4 lib/asker/exporter/export2moodle_xml.rb
asker-tool-2.9.3 lib/asker/exporter/export2moodle_xml.rb
asker-tool-2.9.2 lib/asker/exporter/export2moodle_xml.rb
asker-tool-2.9.1 lib/asker/exporter/export2moodle_xml.rb
asker-tool-2.9.0 lib/asker/exporter/export2moodle_xml.rb