Module: QuestionHashFormatter
- Defined in:
- lib/asker/formatter/question_hash_formatter.rb
Overview
Transform Questions into YAML format
Class Method Summary collapse
Class Method Details
.sanitize(input = '') ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/asker/formatter/question_hash_formatter.rb', line 30 def self.sanitize(input = '') output = input.dup output.gsub!("#", "\\#") output.gsub!("\n", " ") #output.gsub!(":", "\\:") output.gsub!("=", "\\=") output.gsub!("\{", "\\{") output.gsub!("\}", "\\}") output end |
.to_hash(question) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asker/formatter/question_hash_formatter.rb', line 4 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 s[:matching] = @question.matching when :short @question.shorts.uniq! s[:answer] = @question.shorts end s end |