Class: GithubToCanvasQuiz::Model::Answer::ShortAnswer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ShortAnswer

Returns a new instance of ShortAnswer.



9
10
11
12
13
# File 'lib/github_to_canvas_quiz/model/answer/short_answer.rb', line 9

def initialize(options)
  options.each do |key, value|
    send("#{key}=", value) if respond_to?("#{key}=")
  end
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



7
8
9
# File 'lib/github_to_canvas_quiz/model/answer/short_answer.rb', line 7

def comments
  @comments
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/github_to_canvas_quiz/model/answer/short_answer.rb', line 7

def id
  @id
end

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/github_to_canvas_quiz/model/answer/short_answer.rb', line 7

def text
  @text
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/github_to_canvas_quiz/model/answer/short_answer.rb', line 7

def title
  @title
end

Instance Method Details

#to_hObject



23
24
25
26
27
28
29
30
# File 'lib/github_to_canvas_quiz/model/answer/short_answer.rb', line 23

def to_h
  {
    'answer_text' => text,
    'answer_weight' => title == 'Correct' ? 100 : 0,
    'answer_comment_html' => comments,
    'id' => id
  }.reject { |_,v| v.nil? }
end

#to_markdownObject



15
16
17
18
19
20
21
# File 'lib/github_to_canvas_quiz/model/answer/short_answer.rb', line 15

def to_markdown
  MarkdownBuilder.build do |md|
    md.h2(title)
    md.p(text)
    md.blockquote(md.html_to_markdown(comments)) unless comments.empty?
  end
end