Sha256: c874104c840e86a839c19f2f0e0acc8d67e643645d2a8e71081f71dd86593859

Contents?: true

Size: 597 Bytes

Versions: 1

Compression:

Stored size: 597 Bytes

Contents

module Quizzes
  class GameQuestionFactory

    def initialize(params = {})
      @game = params[:game]
      @questions = params[:questions]
      unless @game && @questions && @questions.any?
        raise "It needs a game and a set of questions"
      end
    end

    def generate
      @questions.map do |question|
        Quizzes::GameQuestion.new(
          game: @game, question: question, seed_to_shuffle_answers: generate_seed_for(question)
        )
      end
    end

    private

    def generate_seed_for(question)
      Random.new(question.id + Date.new.day.to_i)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quizzes-0.1.0 app/models/quizzes/game_question_factory.rb