Class: Moodle2CC::CanvasCC::CartridgeCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/moodle2cc/canvas_cc/cartridge_creator.rb

Constant Summary collapse

COURSE_SETTINGS_DIR =
'course_settings'

Instance Method Summary collapse

Constructor Details

#initialize(course) ⇒ CartridgeCreator

Returns a new instance of CartridgeCreator.



6
7
8
# File 'lib/moodle2cc/canvas_cc/cartridge_creator.rb', line 6

def initialize(course)
  @course = course
end

Instance Method Details

#create(out_dir) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/moodle2cc/canvas_cc/cartridge_creator.rb', line 10

def create(out_dir)
  out_file = File.join(out_dir, filename)
  Dir.mktmpdir do |dir|
    write_cartridge(dir)

    tmp_file = File.join(dir, filename)
    zip_dir(tmp_file, dir)
    FileUtils.mv(tmp_file, out_file)
  end
  out_file
end

#filenameObject



22
23
24
25
26
27
28
29
30
# File 'lib/moodle2cc/canvas_cc/cartridge_creator.rb', line 22

def filename
  title = @course.title.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
    gsub(/([a-z\d])([A-Z])/, '\1_\2').
    gsub(/[\/|\.]/, '_').
    tr('- ', '_').downcase.
    gsub(/_{2,}/, '_')
  "#{title}.imscc"
end