Class: Moodle2CC::CanvasCC::ModuleMetaWriter

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

Constant Summary collapse

MODULE_META_FILE =
'module_meta.xml'

Instance Method Summary collapse

Constructor Details

#initialize(work_dir, *canvas_modules) ⇒ ModuleMetaWriter

Returns a new instance of ModuleMetaWriter.



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

def initialize(work_dir, *canvas_modules)
  @work_dir = work_dir
  @canvas_modules = canvas_modules
end

Instance Method Details

#writeObject



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

def write
  xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml.modules(
        'xmlns' => 'http://canvas.instructure.com/xsd/cccv1p0',
        'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
        'xsi:schemaLocation' => 'http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd'
    ) { |xml|
      @canvas_modules.each_with_index { |mod, position| canvas_module(mod, xml, position) }
    }
  end.to_xml
  File.open(File.join(@work_dir, Moodle2CC::CanvasCC::CartridgeCreator::COURSE_SETTINGS_DIR, MODULE_META_FILE), 'w') { |f| f.write(xml) }
end