class GithubToCanvasQuiz::Model::Question
Attributes
answers[RW]
course_id[RW]
description[RW]
distractors[RW]
id[RW]
name[RW]
quiz_id[RW]
sources[RW]
type[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/github_to_canvas_quiz/model/question.rb, line 8 def initialize(options) options.each do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end end
Public Instance Methods
frontmatter_hash()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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
Private Instance Methods
sources_to_html()
click to toggle source
# File lib/github_to_canvas_quiz/model/question.rb, line 53 def sources_to_html comments = sources.map do |source| "<li><a href=\"#{source['url']}\">#{source['name']}</a></li>" end.join "<p><strong>Source/s:</strong><ul>#{comments}</ul></p>" end