Class: GithubToCanvasQuiz::Model::Question
- Inherits:
-
Object
- Object
- GithubToCanvasQuiz::Model::Question
- Defined in:
- lib/github_to_canvas_quiz/model/question.rb
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#course_id ⇒ Object
Returns the value of attribute course_id.
-
#description ⇒ Object
Returns the value of attribute description.
-
#distractors ⇒ Object
Returns the value of attribute distractors.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#quiz_id ⇒ Object
Returns the value of attribute quiz_id.
-
#sources ⇒ Object
Returns the value of attribute sources.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #frontmatter_hash ⇒ Object
-
#initialize(options) ⇒ Question
constructor
A new instance of Question.
- #to_h ⇒ Object
- #to_markdown ⇒ Object
Constructor Details
#initialize(options) ⇒ Question
Returns a new instance of Question.
8 9 10 11 12 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 8 def initialize() .each do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end end |
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def answers @answers end |
#course_id ⇒ Object
Returns the value of attribute course_id.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def course_id @course_id end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def description @description end |
#distractors ⇒ Object
Returns the value of attribute distractors.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def distractors @distractors end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def name @name end |
#quiz_id ⇒ Object
Returns the value of attribute quiz_id.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def quiz_id @quiz_id end |
#sources ⇒ Object
Returns the value of attribute sources.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def sources @sources end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6 def type @type end |
Instance Method Details
#frontmatter_hash ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 41 def frontmatter_hash { 'course_id' => course_id, 'quiz_id' => quiz_id, 'id' => id, 'type' => type, 'sources' => sources } end |
#to_h ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 29 def to_h { 'question_name' => name, 'question_text' => description, 'question_type' => type, 'points_possible' => 1, 'neutral_comments_html' => sources.nil? || sources.empty? ? '' : sources_to_html, 'answers' => answers.map(&:to_h), 'matching_answer_incorrect_matches' => distractors.join("\n") } end |
#to_markdown ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/github_to_canvas_quiz/model/question.rb', line 14 def to_markdown MarkdownBuilder.build do |md| md.frontmatter(frontmatter_hash) md.h1(name) md.md(md.html_to_markdown(description)) answers.each do |answer| md.md(answer.to_markdown) end unless distractors.empty? md.h2('Incorrect') md.ul(*distractors) end end end |