Sha256: ad263ac83cddc33c7e44c305c068a57ab5225cf14ffab48fcfb068c600e20110

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 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, 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.0 app/models/quizzes/game_question.rb