Class: DarwinCore

Inherits:
Object
  • Object
show all
Defined in:
lib/dwc-archive/xml_reader.rb,
lib/dwc-archive.rb,
lib/dwc-archive/core.rb,
lib/dwc-archive/errors.rb,
lib/dwc-archive/archive.rb,
lib/dwc-archive/expander.rb,
lib/dwc-archive/ingester.rb,
lib/dwc-archive/metadata.rb,
lib/dwc-archive/extension.rb,
lib/dwc-archive/generator.rb,
lib/dwc-archive/generator_eml_xml.rb,
lib/dwc-archive/generator_meta_xml.rb,
lib/dwc-archive/classification_normalizer.rb

Overview

Defined Under Namespace

Modules: Ingester, XmlReader Classes: Archive, ClassificationNormalizer, Core, CoreFileError, EncodingError, Error, Expander, Extension, ExtensionFileError, FileNotFoundError, Generator, GeneratorError, GnubTaxon, InvalidArchiveError, Metadata, ParentNotCurrentError, SynonymNormalized, TaxonNormalized, UnpackingError, VernacularNormalized

Constant Summary collapse

VERSION =
open(File.join(File.dirname(__FILE__), '..', 'VERSION')).readline.strip
DEFAULT_TMP_DIR =
"/tmp"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR) ⇒ DarwinCore

Returns a new instance of DarwinCore.



63
64
65
66
67
68
69
# File 'lib/dwc-archive.rb', line 63

def initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR)
  @dwc_path = dwc_path
  @archive = DarwinCore::Archive.new(@dwc_path, tmp_dir)
  @core = DarwinCore::Core.new(self)
  @metadata = DarwinCore::Metadata.new(@archive)
  @extensions = get_extensions
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



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

def archive
  @archive
end

#classification_normalizerObject (readonly)

Returns the value of attribute classification_normalizer.



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

def classification_normalizer
  @classification_normalizer
end

#coreObject (readonly)

Returns the value of attribute core.



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

def core
  @core
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



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

def extensions
  @extensions
end

#metadataObject (readonly) Also known as: eml

Returns the value of attribute metadata.



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

def 
  @metadata
end

Class Method Details

.clean_all(tmp_dir = DEFAULT_TMP_DIR) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/dwc-archive.rb', line 38

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

.loggerObject



47
48
49
# File 'lib/dwc-archive.rb', line 47

def self.logger
  @@logger ||= Logger.new(nil)
end

.logger=(logger) ⇒ Object



51
52
53
# File 'lib/dwc-archive.rb', line 51

def self.logger=(logger)
  @@logger = logger
end

.logger_resetObject



55
56
57
# File 'lib/dwc-archive.rb', line 55

def self.logger_reset
  self.logger = Logger.new(nil)
end

.logger_write(obj_id, message, method = :info) ⇒ Object



59
60
61
# File 'lib/dwc-archive.rb', line 59

def self.logger_write(obj_id, message, method = :info)
  self.logger.send(method, "|%s|%s|" % [obj_id, message])
end

.nil_field?(field) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.nil_field?(field)
  return true if [nil, '', '/N'].include?(field)
  false
end

Instance Method Details

#checksumObject



82
83
84
# File 'lib/dwc-archive.rb', line 82

def checksum
  Digest::SHA1.hexdigest(open(@dwc_path).read)
end

#has_parent_id?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/dwc-archive.rb', line 78

def has_parent_id?
  !!@core.fields.join('|').downcase.match(/highertaxonid|parentnameusageid/)
end

#normalize_classificationObject

generates a hash from a classification data with path to each node, list of synonyms and vernacular names.



72
73
74
75
76
# File 'lib/dwc-archive.rb', line 72

def normalize_classification
  return nil unless has_parent_id?
  @classification_normalizer ||= DarwinCore::ClassificationNormalizer.new(self)
  @classification_normalizer.normalize
end