Sha256: 556fd0f7f0857c2ebf7d8894269ddfc2de31b3d4f458ad2f6d036787d7fda37a

Contents?: true

Size: 946 Bytes

Versions: 1

Compression:

Stored size: 946 Bytes

Contents

require 'nokogiri'
class DarwinCore
  class Archive
    attr_reader :meta, :eml
    def initialize(archive_path, tmp_dir)
      @archive_path = archive_path
      @tmp_dir = tmp_dir
      @expander = DarwinCore::Expander.new(@archive_path, @tmp_dir)
      @expander.unpack
      if valid?
        @meta = DarwinCore::XmlReader.
          from_xml(open(File.join(@expander.path, 'meta.xml')))
        @eml = files.include?("eml.xml") ? 
          DarwinCore::XmlReader.
            from_xml(open(File.join(@expander.path, 'eml.xml'))) : nil
      else
        clean
        raise InvalidArchiveError
      end
    end

    def valid?
      valid = true
      valid = valid && @expander.path && FileTest.exists?(@expander.path)
      valid = valid && files && files.include?('meta.xml')
    end
    
    def files
      @expander.files
    end

    def files_path
      @expander.path
    end

    def clean
      @expander.clean
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dwc-archive-0.9.10 lib/dwc-archive/archive.rb