Class: TriviaFactory::CompanyQuestion
- Defined in:
- lib/trivia_factory/company_question.rb
Constant Summary
Constants inherited from Question
Question::ANSWER_TYPES, Question::QUESTION_TYPES
Instance Attribute Summary
Attributes inherited from Question
#answer, #answer_type, #choices, #label, #question_type
Class Method Summary collapse
Methods inherited from Question
academy_awards, capital_cities, company, fetch_csv, #initialize, math, question_types, random, sports, #to_h, us_state_capitals, vocabulary
Constructor Details
This class inherits a constructor from TriviaFactory::Question
Class Method Details
.generate ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/trivia_factory/company_question.rb', line 5 def generate # File: sp_500.csv # Column 0: ticker # Column 1: company name # Column 2: sector # Column 3: sub sector # Column 4: HQ location data = fetch_csv('sp_500') answer_row = data.sample question = TriviaFactory::Question.new question.label = "Headquartered in #{answer_row[4]}, this public company has the ticker symbol #{answer_row[0]}" question.choices = [answer_row[1]] question.question_type = :multiple_choice question.answer_type = :choice_index loop do row = data.sample question.choices << row[1] if question.choices.index(row[1]).nil? break if question.choices.size == 4 end question.choices.shuffle! question.answer = question.choices.index(answer_row[1]) question end |