Sha256: a85aab51d1bf1fda9da51f454f487a6fa88c25b2bead4e38dc5833ac285bd196

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: false

require 'erb'
require_relative '../application'

# Transform Questions into Gift format
class QuestionMoodleFormatter
  ##
  # Convert question object into gift formatted string
  # @param question (Question)
  # @return String
  def self.to_s(question)
    case question.type
    when :choice
      fractions = Application.instance.config['questions']['fractions']
      penalties = fractions
      # penalties = ['', '-50', '-33.33333', '-25', '-20']
      # puts "[DEBUG] fractions : #{fractions}"
      # puts "[DEBUG] penalties : #{penalties}"

      penalty = penalties[question.bads.size]
      template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'multichoice.erb'))
    when :boolean
      template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'truefalse.erb'))
    when :match
      template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'matching.erb'))
    when :short
      template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'shortanswer.erb'))
    end
    renderer = ERB.new(template)
    renderer.result(binding)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
asker-tool-2.6.0 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.9 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.8 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.7 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.6 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.5 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.4 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.3 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.2 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.1 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.5.0 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.4.5 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.4.4 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.4.3 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.4.2 lib/asker/formatter/question_moodle_formatter.rb
asker-tool-2.4.1 lib/asker/formatter/question_moodle_formatter.rb