Sha256: 8cb7b8cd554f4688842802028e44b7713adaaa18c696bd80274a8fd38a2d066f

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# encoding: UTF-8
$:.unshift(File.dirname(__FILE__)) unless
   $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))   
require 'ruby_extensions'
require 'fileutils'
begin
  require 'fastercsv'
  CSV = FasterCSV
rescue LoadError
  require 'csv'
end
require 'dwc-archive/ingester'
require 'dwc-archive/errors'
require 'dwc-archive/expander'
require 'dwc-archive/archive'
require 'dwc-archive/core'
require 'dwc-archive/extension'
require 'dwc-archive/metadata'

class DarwinCore
  attr_reader :archive, :core, :metadata, :extensions
  alias :eml :metadata
  
  DEFAULT_TMP_DIR = "/tmp"
  
  def initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR)
    @archive = DarwinCore::Archive.new(dwc_path, tmp_dir) 
    @core = DarwinCore::Core.new(@archive)
    @metadata = DarwinCore::Metadata.new(@archive)
    @extensions = get_extensions
  end

  def self.clean_all(tmp_dir = DEFAULT_TMP_DIR)
    Dir.entries(tmp_dir).each do |entry|
      path = File.join(tmp_dir, entry)
      if FileTest.directory?(path) && entry.match(/^dwc_[\d]+$/)
        FileUtils.rm_rf(path)
      end
    end
  end

  private
  def get_extensions
    res = []
    root_key = @archive.meta.keys[0]
    ext = @archive.meta[root_key][:extension]
    return [] unless ext
    ext = [ext] if ext.class != Array
    ext.map { |e| DarwinCore::Extension.new(@archive, e) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dwc-archive-0.2.3 lib/dwc-archive.rb
dwc-archive-0.2.2 lib/dwc-archive.rb
dwc-archive-0.2.1 lib/dwc-archive.rb