4bbd93ded1
Adding the .ruby-verison file triggered previously un-run cops, specifically: This cop is designed to help upgrade to Ruby 3.0. It will add the comment `# frozen_string_literal: true` to the top of files to enable frozen string literals. Frozen string literals will be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+. More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
33 lines
1.1 KiB
Ruby
33 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
class CandidateQuiz
|
|
attr_reader :candidate_id
|
|
|
|
def initialize candidate
|
|
@candidate_id = candidate.to_i
|
|
end
|
|
|
|
def fetch_question qid
|
|
questions = raw_quiz(qid).each_with_object([]) { |row, quiz| quiz << CandidateQuizQuestion.new(row) }
|
|
questions.first
|
|
end
|
|
|
|
def build_my_quiz
|
|
raw_quiz.each_with_object([]) { |row, quiz| quiz << CandidateQuizQuestion.new(row) }
|
|
end
|
|
|
|
private
|
|
|
|
def raw_quiz qid = nil
|
|
question = qid.nil? ? "" : " and q.id = #{qid} "
|
|
sql = "select c.id candidate_id, q.quiz_id, q.id question_id, a.id answer_id, q.sort
|
|
, q.question, q.attachment, q.category, q.input_type, q.input_options, a.answer
|
|
, ifnull(a.saved, false) saved, ifnull(a.submitted, false) submitted , a.updated_at
|
|
from candidates c
|
|
inner join questions q on q.quiz_id = c.quiz_id
|
|
left join answers a on a.candidate_id = c.id AND a.question_id = q.id
|
|
where q.active = true and c.id = #{candidate_id} #{question}
|
|
order by q.sort;"
|
|
ActiveRecord::Base.connection.exec_query(sql)
|
|
end
|
|
end
|