Class: GithubToCanvasQuiz::Model::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/github_to_canvas_quiz/model/question.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  options.each do |key, value|
    send("#{key}=", value) if respond_to?("#{key}=")
  end
end

Instance Attribute Details

#answersObject

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_idObject

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

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6

def description
  @description
end

#distractorsObject

Returns the value of attribute distractors.



6
7
8
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6

def distractors
  @distractors
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6

def id
  @id
end

#nameObject

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_idObject

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

#sourcesObject

Returns the value of attribute sources.



6
7
8
# File 'lib/github_to_canvas_quiz/model/question.rb', line 6

def sources
  @sources
end

#typeObject

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_hashObject



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_hObject



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_markdownObject



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