Sha256: 17f757545149ab8b22659820cd57a65eed95665f56c3c32e3b8a7f79ad2d958d

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# == Schema Information
#
# Table name: quizzes_game_questions
#
#  id                      :integer          not null, primary key
#  game_id                 :integer
#  question_id             :integer
#  seed_to_shuffle_answers :integer
#  created_at              :datetime         not null
#  updated_at              :datetime         not null
#

require_dependency "quizzes/application_record"

module Quizzes
  class GameQuestion < ApplicationRecord

    belongs_to :game, foreign_key: "game_id", class_name: Quizzes::Game
    belongs_to :question, foreign_key: "question_id", class_name: Quizzes::Question

    validates :game, :question, :seed_to_shuffle_answers, presence: true

    def correct? answer_id
      question.correct_answer.id == answer_id
    end

    def answers
      [
        {id: question.answers[0].id, text: question.answers[0].text},
        {id: question.answers[1].id, text: question.answers[1].text},
        {id: question.answers[2].id, text: question.answers[2].text},
        {id: question.answers[3].id, text: question.answers[3].text}
      ].shuffle(random: seed_to_shuffle_answers)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quizzes-0.1.1 app/models/quizzes/game_question.rb