Class: Barker::Api::Response::CandidateQuestion

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/barker/api/response/candidate_question.rb

Instance Method Summary collapse

Methods inherited from Base

#error?, #ok?

Instance Method Details

#answersObject



9
10
11
# File 'lib/barker/api/response/candidate_question.rb', line 9

def answers
  candidate_question.answers.map { |candidate_answer| build_candidate_answer(candidate_answer) }
end

#given_answerObject



13
14
15
# File 'lib/barker/api/response/candidate_question.rb', line 13

def given_answer
  build_candidate_answer(candidate_question.given_answer)
end

#to_hashObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/barker/api/response/candidate_question.rb', line 17

def to_hash
  {
    'id'            => id,
    'question_id'   => question_id,
    'candidate_id'  => candidate_id,
    'label'         => label,
    'state'         => state,
    'asked_at'      => to_i(asked_at),
    'answered_at'   => to_i(answered_at),
    'asked?'        => asked?, 
    'answered?'     => answered?,
    'open?'         => open?,
    'time_left'     => time_left,
    'timeout?'      => timeout?,
    'correct?'      => correct?,
    'wrong?'        => wrong?,
    'answers'       => answers.map(&:to_hash),
    'given_answer'  => given_answer? && given_answer.to_hash
  }
end