Class: Question2Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/formatter/question2hash.rb

Instance Method Summary collapse

Instance Method Details

#format(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
29
30
31
32
# File 'lib/asker/formatter/question2hash.rb', line 4

def format(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)
  case @question.type
  when :boolean
    s[:answer] = @question.good
  when :choice
    s[:answer] = sanitize(@question.good)
    s[:options] = (@question.bads + [@question.good]).shuffle
  when :ddmatch
    s[:answer] = @question.matching
  when :match
    s[:answer] = @question.matching
  when :ordering
    s[:answer] = @question.ordering
  when :short
    @question.shorts.uniq!
    s[:answer] = @question.shorts
  else
    Logger.warn "[WARN] Question2Hash: Unkown type (#{@question.type})"
  end
  s
end