class DarwinCore
main class for handling darwin core archives
Version constant of the class
Constants
- DEFAULT_TMP_DIR
- SynonymNormalized
- VERSION
- VernacularNormalized
Attributes
logger[W]
archive[R]
classification_normalizer[R]
core[R]
eml[R]
metadata[R]
Public Class Methods
clean(path)
click to toggle source
# File lib/dwc_archive.rb, line 36 def clean(path) FileUtils.rm_rf(path) if FileTest.exist?(path) end
clean_all(tmp_dir = DEFAULT_TMP_DIR)
click to toggle source
# File lib/dwc_archive.rb, line 60 def self.clean_all(tmp_dir = DEFAULT_TMP_DIR) Dir.entries(tmp_dir).each do |entry| path = File.join(tmp_dir, entry) FileUtils.rm_rf(path) if FileTest.directory?(path) && entry.match(/^dwc_\d+$/) end end
files(path)
click to toggle source
# File lib/dwc_archive.rb, line 40 def files(path) return nil unless path && FileTest.exist?(path) Dir.entries(path).reject { |e| e.match(/[.]{1,2}$/) }.sort end
logger()
click to toggle source
# File lib/dwc_archive.rb, line 67 def self.logger @logger ||= Logger.new(nil) end
logger_reset()
click to toggle source
# File lib/dwc_archive.rb, line 71 def self.logger_reset self.logger = Logger.new(nil) end
logger_write(obj_id, message, method = :info)
click to toggle source
# File lib/dwc_archive.rb, line 75 def self.logger_write(obj_id, message, method = :info) logger.send(method, "|#{obj_id}|#{message}|") end
new(dwc_path, tmp_dir = DEFAULT_TMP_DIR)
click to toggle source
# File lib/dwc_archive.rb, line 79 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 end
nil_field?(field)
click to toggle source
# File lib/dwc_archive.rb, line 54 def self.nil_field?(field) return true if [nil, "", "/N"].include?(field) false end
random_path(tmp_dir)
click to toggle source
# File lib/dwc_archive.rb, line 46 def random_path(tmp_dir) File.join(tmp_dir, "dwc_#{rand(10_000_000_000)}") end
Public Instance Methods
checksum()
click to toggle source
# File lib/dwc_archive.rb, line 110 def checksum Digest::SHA1.hexdigest(File.read(@dwc_path)) end
extensions()
click to toggle source
# File lib/dwc_archive.rb, line 114 def extensions return @extensions if @extensions root_key = @archive.meta.keys[0] ext = @archive.meta[root_key][:extension] return @extensions = [] unless ext ext = [ext] if ext.class != Array @extensions = ext.map { |e| DarwinCore::Extension.new(self, e) } end
file_name()
click to toggle source
# File lib/dwc_archive.rb, line 87 def file_name File.split(@dwc_path).last end
normalize_classification()
click to toggle source
generates a hash from a classification data with path to each node, list of synonyms and vernacular names.
# File lib/dwc_archive.rb, line 97 def normalize_classification return nil unless parent_id? @classification_normalizer ||= DarwinCore::ClassificationNormalizer.new(self) @classification_normalizer.normalize end
parent_id?()
click to toggle source
# File lib/dwc_archive.rb, line 105 def parent_id? !@core.fields.join("|"). downcase.match(/highertaxonid|parentnameusageid/).nil? end
path()
click to toggle source
# File lib/dwc_archive.rb, line 91 def path File.expand_path(@dwc_path) end