Class: CommonCartridge::Parsers::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/common_cartridge/parsers/parser.rb

Defined Under Namespace

Classes: ManifestDocument

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zipfile) ⇒ Parser

Returns a new instance of Parser.



27
28
29
30
# File 'lib/common_cartridge/parsers/parser.rb', line 27

def initialize(zipfile)
  @zipfile = zipfile
  @package = Package.new
end

Class Method Details

.use_file(zipfile, path) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/common_cartridge/parsers/parser.rb', line 18

def self.use_file(zipfile, path)
  Zip::File.open(File.join(CommonCartridge.config.import_directory, zipfile)) do |file|
    f = file.glob(path).first
    unless f.nil?
      yield f.get_input_stream.read
    end
  end
end

Instance Method Details

#parseObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/common_cartridge/parsers/parser.rb', line 32

def parse
  Parser.use_file(@zipfile, 'imsmanifest.xml') do |xml|
    @package.manifest = ManifestDocument.parse(xml).manifest
  end

  parse_content!
  @package.outcomes = parse_outcomes
  parse_questions!
  parse_module_items!
  @package
end