class Question
This is a question object. Question
objects are created based on the user choice (either random or category). A JSON hash is returned from the openTDB GET request and stored in each question object.
Attributes
category[RW]
correct_answer[RW]
difficulty[RW]
incorrect_answers[RW]
question[RW]
type[RW]
Public Class Methods
all()
click to toggle source
# File lib/cli_trivia/question.rb, line 28 def self.all @@all end
clear_all()
click to toggle source
# File lib/cli_trivia/question.rb, line 32 def self.clear_all @@all.clear end
new(question_data)
click to toggle source
Because all metadata regarding a question is available on creation of each Question
Object, it is populated upon initialization and not after.
# File lib/cli_trivia/question.rb, line 12 def initialize(question_data) @category = add_category(question_data['category']) @type = question_data['type'] @difficulty = question_data['difficulty'] @question = Question.format_string(question_data['question']) @correct_answer = question_data['correct_answer'] @incorrect_answers = question_data['incorrect_answers'] @@all << self end
Public Instance Methods
add_category(name)
click to toggle source
Allows for the adding of a Category
Object to self. A question BELONGS to a category.
# File lib/cli_trivia/question.rb, line 23 def add_category(name) category = Category.find_or_create_by_name(name) category.add_question(self) end