Class: Word2Quiz::Quiz
- Inherits:
-
Object
- Object
- Word2Quiz::Quiz
- Defined in:
- lib/word_2_quiz/quiz.rb
Overview
Quiz contains all quiz data. A quiz has a description, a title, a time limit, and questions.
Constant Summary collapse
- ALLOWED_ATTEMPTS =
1
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#questions ⇒ Object
Returns the value of attribute questions.
-
#time_limit ⇒ Object
Returns the value of attribute time_limit.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title:, time_limit:, description: "") ⇒ Quiz
constructor
A new instance of Quiz.
- #questions_as_canvas ⇒ Object
- #to_canvas ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(title:, time_limit:, description: "") ⇒ Quiz
Returns a new instance of Quiz.
15 16 17 18 19 20 |
# File 'lib/word_2_quiz/quiz.rb', line 15 def initialize(title:, time_limit:, description: "") @questions = [] @description = description @title = title @time_limit = time_limit end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
11 12 13 |
# File 'lib/word_2_quiz/quiz.rb', line 11 def description @description end |
#questions ⇒ Object
Returns the value of attribute questions.
11 12 13 |
# File 'lib/word_2_quiz/quiz.rb', line 11 def questions @questions end |
#time_limit ⇒ Object
Returns the value of attribute time_limit.
11 12 13 |
# File 'lib/word_2_quiz/quiz.rb', line 11 def time_limit @time_limit end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/word_2_quiz/quiz.rb', line 11 def title @title end |
Class Method Details
.from_paragraphs(paragraphs, answers) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/word_2_quiz/quiz.rb', line 22 def self.from_paragraphs(paragraphs, answers) all_question_paragraphs = Quiz.get_question_paragraphs(paragraphs) quiz_title = Helpers.get_quiz_title(paragraphs) quiz_description = Helpers.get_quiz_description(paragraphs) quiz_duration = Helpers.get_quiz_duration(paragraphs) quiz = Quiz.new( title: quiz_title, time_limit: quiz_duration, description: quiz_description, ) all_question_paragraphs.each do |question_paragraphs| question_number = Helpers.get_question_number(question_paragraphs) question = Question.from_paragraphs( question_paragraphs, answers[question_number], ) quiz.questions.push(question) end quiz end |
.get_question_paragraphs(paragraphs) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/word_2_quiz/quiz.rb', line 48 def self.get_question_paragraphs(paragraphs) question_start_index = Helpers.get_question_start_index(paragraphs) question_end_index = Helpers.get_question_end_index(paragraphs) question_range = paragraphs[question_start_index...question_end_index] question_indexes = Helpers.get_question_indexes(question_range) Helpers.map_to_boundaries( indexes: question_indexes, paragraphs: question_range, ) end |
Instance Method Details
#questions_as_canvas ⇒ Object
83 84 85 |
# File 'lib/word_2_quiz/quiz.rb', line 83 def questions_as_canvas @questions.map(&:to_canvas) end |
#to_canvas ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/word_2_quiz/quiz.rb', line 71 def to_canvas { title: @title, question_count: @questions.count, points_possible: @questions.count * Question::POINTS_POSSIBLE, quiz_type: "assignment", description: @description, allowed_attempts: ALLOWED_ATTEMPTS, time_limit: @time_limit, } end |
#to_h ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/word_2_quiz/quiz.rb', line 62 def to_h { title: @title, questions: @questions.map(&:to_h), description: @description, time_limit: @time_limit, } end |