class TriviaFactory::Question

Constants

ANSWER_TYPES
QUESTION_TYPES

Attributes

answer[RW]
answer_type[RW]
choices[RW]
label[RW]
question_type[RW]

Public Class Methods

academy_awards() click to toggle source
# File lib/trivia_factory.rb, line 65
def academy_awards
  TriviaFactory::AcademyAwardsQuestion.generate
end
capital_cities() click to toggle source
# File lib/trivia_factory.rb, line 57
def capital_cities
  TriviaFactory::CapitalCitiesQuestion.generate
end
company() click to toggle source
# File lib/trivia_factory.rb, line 73
def company
  TriviaFactory::CompanyQuestion.generate
end
fetch_csv(name) click to toggle source
# File lib/trivia_factory.rb, line 77
def fetch_csv(name)
  file = File.join(File.dirname(__FILE__), "data", "#{name}.csv")
  CSV.read(file)
end
generate() click to toggle source
# File lib/trivia_factory.rb, line 45
def generate
  TriviaFactory::Question.new
end
math() click to toggle source
# File lib/trivia_factory.rb, line 49
def math
  TriviaFactory::MathQuestion.generate
end
new() click to toggle source
# File lib/trivia_factory.rb, line 16
def initialize
  @label = "Who won the MLB World Series in 2016?"
  @question_type = :multiple_choice
  @choices = ["San Francisco Giants", "Chicago Cubs", "Cleveland Indians", "Golden State Warriors"]
  @answer_type = :choice_index
  @answer = 1
end
question_types() click to toggle source
# File lib/trivia_factory.rb, line 36
def question_types
  TriviaFactory.constants.select { |k| TriviaFactory.const_get(k).instance_of?(Class) && k != :Question }
end
random() click to toggle source
# File lib/trivia_factory.rb, line 40
def random
  klass = question_types.sample
  TriviaFactory.const_get(klass).generate
end
sports() click to toggle source
# File lib/trivia_factory.rb, line 61
def sports
  TriviaFactory::SportsQuestion.generate
end
us_state_capitals() click to toggle source
# File lib/trivia_factory.rb, line 53
def us_state_capitals
  TriviaFactory::UsStateCapitalsQuestion.generate
end
vocabulary() click to toggle source
# File lib/trivia_factory.rb, line 69
def vocabulary
  TriviaFactory::VocabularyQuestion.generate
end

Public Instance Methods

to_h() click to toggle source
# File lib/trivia_factory.rb, line 24
def to_h
  {
    label: @label,
    question_type: @question_type,
    choices: @choices,
    answer: @answer,
    answer_type: @answer_type
  }
end