class GithubToCanvasQuiz::Parser::Canvas::Quiz

Parses a quiz from the Canvas API and returns a Quiz

Attributes

data[R]

Public Class Methods

new(data) click to toggle source
# File lib/github_to_canvas_quiz/parser/canvas/quiz.rb, line 12
def initialize(data)
  @data = data
end

Public Instance Methods

parse() click to toggle source
# File lib/github_to_canvas_quiz/parser/canvas/quiz.rb, line 16
def parse
  Model::Quiz.new(
    course_id: data['course_id'],
    id: data['id'],
    repo: repo,
    title: data['title'],
    description: description
  )
end

Private Instance Methods

description() click to toggle source

Remove header elements

# File lib/github_to_canvas_quiz/parser/canvas/quiz.rb, line 29
def description
  nodes = Nokogiri::HTML5.fragment(data['description'])
  nodes.css('#git-data-element').remove
  nodes.css('.fis-header').remove
  nodes.to_html.strip
end
repo() click to toggle source

Parse the repo from the git-data-element

# File lib/github_to_canvas_quiz/parser/canvas/quiz.rb, line 37
def repo
  data_element = Nokogiri::HTML5.fragment(data['description']).css('#git-data-element').first
  data_element ? data_element['data-repo'] : nil
end