Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

vistahigherlearning / common_cartridge   ruby

Repository URL to install this package:

Version: 1.0.1 

/ lib / common_cartridge / parsers / files.rb

module CommonCartridge
  module Parsers
    class Files
      attr_reader :resource

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

      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

      private
      def resource_to_mapping(resource)
        CommonCartridge::Elements::Resources.type_mappings.detect { |regex, klass| resource.type =~ regex }
      end
    end
  end
end