Sha256: af9d224c16e9fe1301861b593d7490a0e910093ec1a4e89ebf837d4f5e2d6edd
Contents?: true
Size: 1010 Bytes
Versions: 4
Compression:
Stored size: 1010 Bytes
Contents
# Transform Questions into YAML format module QuestionHashFormatter def self.to_hash(question) @question = question # Return question using YAML format s = {} s[:comment] = @question.comment s[:name] = @question.name s[:text] = sanitize(@question.text) s[:type] = @question.type s[:feedback] = sanitize(@question.feedback.to_s) s[:lang] = @question.lang.code.to_sym case @question.type when :choice s[:answer] = sanitize(@question.good) s[:options] = (@question.bads + [@question.good]).shuffle when :boolean s[:answer] = @question.good when :match s[:answer] = @question.matching when :short @question.shorts.uniq! s[:answer] = @question.shorts end s end def self.sanitize(input = "") output = input.dup output.gsub!("#", "\\#") output.tr!("\n", " ") # output.gsub!(":", "\\:") output.gsub!("=", "\\=") output.gsub!("{", "\\{") output.gsub!("}", "\\}") output end end
Version data entries
4 entries across 4 versions & 1 rubygems