Sha256: f7fb780c97c6df13a20809ec4be7f85836d98e45dc6dd1a67488033f92fd70fe

Contents?: true

Size: 877 Bytes

Versions: 33

Compression:

Stored size: 877 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 = Hash.from_xml(open(File.join(@expander.path, 'meta.xml')))
        @eml = files.include?("eml.xml") ? Hash.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

33 entries across 33 versions & 1 rubygems

Version Path
dwc-archive-0.5.9 lib/dwc-archive/archive.rb
dwc-archive-0.5.8 lib/dwc-archive/archive.rb
dwc-archive-0.5.7 lib/dwc-archive/archive.rb
dwc-archive-0.5.6 lib/dwc-archive/archive.rb
dwc-archive-0.5.5 lib/dwc-archive/archive.rb
dwc-archive-0.5.4 lib/dwc-archive/archive.rb
dwc-archive-0.5.3 lib/dwc-archive/archive.rb
dwc-archive-0.5.2 lib/dwc-archive/archive.rb
dwc-archive-0.5.1 lib/dwc-archive/archive.rb
dwc-archive-0.5.0 lib/dwc-archive/archive.rb
dwc-archive-0.4.14 lib/dwc-archive/archive.rb
dwc-archive-0.4.13 lib/dwc-archive/archive.rb
dwc-archive-0.4.12 lib/dwc-archive/archive.rb
dwc-archive-0.4.11 lib/dwc-archive/archive.rb
dwc-archive-0.4.10 lib/dwc-archive/archive.rb
dwc-archive-0.4.9 lib/dwc-archive/archive.rb
dwc-archive-0.4.8 lib/dwc-archive/archive.rb
dwc-archive-0.4.7 lib/dwc-archive/archive.rb
dwc-archive-0.4.6 lib/dwc-archive/archive.rb
dwc-archive-0.4.5 lib/dwc-archive/archive.rb