Class: GithubToCanvasQuiz::Synchronizer::Quiz

Inherits:
Object
  • Object
show all
Defined in:
lib/github_to_canvas_quiz/synchronizer/quiz.rb

Overview

Synchronize a quiz to Canvas based on the contents of a given directory Given a directory with valid markdown files:

phase-1-quiz-arrays | questions | |– 00.md | |– 01.md |– README.md

Useage:

client = CanvasAPI::Client.new(host: host, api_key: api_key)
Synchronizer::Quiz.new(client, 'phase-1-quiz-arrays')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, path) ⇒ Quiz

Returns a new instance of Quiz.



22
23
24
25
26
27
28
29
30
31
# File 'lib/github_to_canvas_quiz/synchronizer/quiz.rb', line 22

def initialize(client, path)
  path = File.expand_path(path)
  raise DirectoryNotFoundError unless Pathname(path).directory?
  
  @client = client
  @path = path
  @repo = RepositoryInterface.new(path)
  @quiz = parse_quiz
  @questions_with_path = parse_questions_with_path if @quiz.id
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/github_to_canvas_quiz/synchronizer/quiz.rb', line 20

def client
  @client
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/github_to_canvas_quiz/synchronizer/quiz.rb', line 20

def path
  @path
end

#questions_with_pathObject (readonly)

Returns the value of attribute questions_with_path.



20
21
22
# File 'lib/github_to_canvas_quiz/synchronizer/quiz.rb', line 20

def questions_with_path
  @questions_with_path
end

#quizObject (readonly)

Returns the value of attribute quiz.



20
21
22
# File 'lib/github_to_canvas_quiz/synchronizer/quiz.rb', line 20

def quiz
  @quiz
end

#repoObject (readonly)

Returns the value of attribute repo.



20
21
22
# File 'lib/github_to_canvas_quiz/synchronizer/quiz.rb', line 20

def repo
  @repo
end

Instance Method Details

#syncObject



33
34
35
36
37
38
# File 'lib/github_to_canvas_quiz/synchronizer/quiz.rb', line 33

def sync
  backup_canvas_to_json! if @quiz.id
  sync_quiz!
  sync_questions!
  backup_canvas_to_json!
end