Sha256: 4fcc644ec8020797d37978dcd2c383a986afd6073b6f3dcdb9be6bcc2b08a40e

Contents?: true

Size: 636 Bytes

Versions: 1

Compression:

Stored size: 636 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.each do |question|
        @game.game_questions.build({ game: @game, question: question, seed_to_shuffle_answers: generate_seed_for(question) })
      end
      @game.game_questions
    end

    private

    def generate_seed_for(question)
      (Random.new(question.id + DateTime.current.day.to_i).rand * 100).to_i
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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