Class: Ruql::Olx::ExportedEdxCourse

Inherits:
Object
  • Object
show all
Defined in:
lib/ruql/olx/exported_edx_course.rb

Instance Method Summary collapse

Constructor Details

#initialize(quiz, chapter_name, course_root, course_options, dryrun: false) ⇒ ExportedEdxCourse

Returns a new instance of ExportedEdxCourse.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruql/olx/exported_edx_course.rb', line 8

def initialize(quiz, chapter_name, course_root, course_options, dryrun: false)
  @dryrun = dryrun
  @course_options = course_options
  @quiz = quiz
  @root = course_root
  verify_writable_dir(@problem_dir = File.join(@root, 'drafts', 'problem'))
  verify_writable_dir(@vertical_dir = File.join(@root, 'drafts', 'vertical'))
  verify_writable_dir(@sequential_dir = File.join(@root, 'sequential'))
  @chapter_file = find_chapter_file(chapter_name)
  @course_name = find_course_name
  @created_files = []       # to delete in case of error, or list created
  @modified_files = []
  @problem_ids = []
  @sequential_id = uuid()
  @vertical_id = uuid()
end

Instance Method Details

#add_problem(xml_text) ⇒ Object

Create a file containing a single problem and remember its UUID.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruql/olx/exported_edx_course.rb', line 26

def add_problem(xml_text)
  url = uuid()
  problem_file = File.join(@problem_dir, "#{url}.xml")
  begin
    File.open(problem_file, 'w') { |f|  f.puts xml_text  }
    @problem_ids << url
    @created_files << problem_file
  rescue StandardError => e
    cleanup
    raise IOError.new(:message => e.message)
  end
end

#add_quizObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/ruql/olx/exported_edx_course.rb', line 39

def add_quiz
  begin
    create_sequential
    create_vertical
    append_quiz_to_chapter
  rescue StandardError => e
    cleanup
    raise IOError.new(:message => e.message)
  end
end

#reportObject



50
51
52
53
54
55
56
57
# File 'lib/ruql/olx/exported_edx_course.rb', line 50

def report
  report = ["Files created:"]
  @created_files.each { |f| report << "  #{f}" }
  report << "Files modified:"
  @modified_files.each { |f| report << "  #{f}" }
  cleanup if @dryrun
  report.join("\n")
end