Class: DarwinCore::Expander

Inherits:
Object
  • Object
show all
Defined in:
lib/dwc-archive/expander.rb

Instance Method Summary collapse

Constructor Details

#initialize(archive_path, tmp_dir) ⇒ Expander

Returns a new instance of Expander.



3
4
5
6
7
8
# File 'lib/dwc-archive/expander.rb', line 3

def initialize(archive_path, tmp_dir)
  @archive_path = archive_path
  @tmp_dir = tmp_dir
  @path = File.join(tmp_dir, 'dwc_' + rand(10000000000).to_s)
  @unpacker = get_unpacker
end

Instance Method Details

#cleanObject



21
22
23
# File 'lib/dwc-archive/expander.rb', line 21

def clean
  FileUtils.rm_rf(@path) if FileTest.exists?(@path)
end

#filesObject



25
26
27
28
# File 'lib/dwc-archive/expander.rb', line 25

def files
  return nil unless path && FileTest.exists?(path)
  Dir.entries(path).select {|e| e !~ /[\.]{1,2}$/}.sort
end

#pathObject



17
18
19
# File 'lib/dwc-archive/expander.rb', line 17

def path
  @files_path ||= files_path
end

#unpackObject



10
11
12
13
14
15
# File 'lib/dwc-archive/expander.rb', line 10

def unpack
  clean
  raise DarwinCore::FileNotFoundError unless File.exists?(@archive_path)
  success = @unpacker.call(@path, @archive_path) if @unpacker
  (@unpacker && success && $?.exitstatus == 0) ? success : (clean; raise DarwinCore::UnpackingError)
end