Class: CommonCartridge::Parsers::Files

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zipfile, resource) ⇒ Files

Returns a new instance of Files.



6
7
8
9
# File 'lib/common_cartridge/parsers/files.rb', line 6

def initialize(zipfile, resource)
  @zipfile = zipfile
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/common_cartridge/parsers/files.rb', line 4

def resource
  @resource
end

Instance Method Details

#parse!(package) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/common_cartridge/parsers/files.rb', line 11

def parse!(package)
  if mapping = resource_to_mapping(resource)
    resource.files.each do |f|
      Parser.use_file(@zipfile, f.href) do |xml|
        f.content = mapping.last.parse(xml)
        f.content.identifier = resource.identifier
        if resource.type =~ CommonCartridge::Elements::Resources::Assignment.pattern && f.href =~ /assignment.*xml/ && !(resource.href =~ /course/)
          doc = Nokogiri::XML(xml)
          doc.remove_namespaces!
          f.content.points_possible = doc.xpath('//points_possible').text
          package.assignments << f.content
        end
      end
    end
  end
end