Class: DarwinCore::Archive

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive_path, tmp_dir) ⇒ Archive

Returns a new instance of Archive.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dwc-archive/archive.rb', line 5

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

Instance Attribute Details

#emlObject (readonly)

Returns the value of attribute eml.



4
5
6
# File 'lib/dwc-archive/archive.rb', line 4

def eml
  @eml
end

#metaObject (readonly)

Returns the value of attribute meta.



4
5
6
# File 'lib/dwc-archive/archive.rb', line 4

def meta
  @meta
end

Instance Method Details

#cleanObject



33
34
35
# File 'lib/dwc-archive/archive.rb', line 33

def clean
  @expander.clean
end

#filesObject



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

def files
  @expander.files
end

#files_pathObject



29
30
31
# File 'lib/dwc-archive/archive.rb', line 29

def files_path
  @expander.path
end

#valid?Boolean

Returns:

  • (Boolean)


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

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