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/version.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

USAGE: Hash.from_xml:(YOUR_XML_STRING) modified from stackoverflow.com/questions/1230741/ convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297

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

DEFAULT_TMP_DIR =
"/tmp"
VERSION =
"0.9.11"

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.



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

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.



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

def archive
  @archive
end

#classification_normalizerObject (readonly)

Returns the value of attribute classification_normalizer.



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

def classification_normalizer
  @classification_normalizer
end

#coreObject (readonly)

Returns the value of attribute core.



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

def core
  @core
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



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

def extensions
  @extensions
end

#metadataObject (readonly) Also known as: eml

Returns the value of attribute metadata.



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

def 
  @metadata
end

Class Method Details

.clean_all(tmp_dir = DEFAULT_TMP_DIR) ⇒ Object



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

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



49
50
51
# File 'lib/dwc-archive.rb', line 49

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

.logger=(logger) ⇒ Object



53
54
55
# File 'lib/dwc-archive.rb', line 53

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

.logger_resetObject



57
58
59
# File 'lib/dwc-archive.rb', line 57

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

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



61
62
63
# File 'lib/dwc-archive.rb', line 61

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)


35
36
37
38
# File 'lib/dwc-archive.rb', line 35

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

Instance Method Details

#checksumObject



94
95
96
# File 'lib/dwc-archive.rb', line 94

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

#file_nameObject



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

def file_name
  File.split(@dwc_path).last
end

#has_parent_id?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/dwc-archive.rb', line 90

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.



83
84
85
86
87
88
# File 'lib/dwc-archive.rb', line 83

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

#pathObject



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

def path
  File.expand_path(@dwc_path)
end