Class: DarwinCore
- Inherits:
-
Object
show all
- Defined in:
- 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/gnub_taxon.rb,
lib/dwc_archive/xml_reader.rb,
lib/dwc_archive/taxon_normalized.rb,
lib/dwc_archive/generator_eml_xml.rb,
lib/dwc_archive/generator_meta_xml.rb,
lib/dwc_archive/classification_normalizer.rb
Overview
Version constant of the class
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 =
"1.1.9"
Class Attribute Summary collapse
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.
Class Attribute Details
.logger ⇒ Object
67
68
69
|
# File 'lib/dwc_archive.rb', line 67
def self.logger
@logger ||= Logger.new(nil)
end
|
Instance Attribute Details
#archive ⇒ Object
Returns the value of attribute archive.
51
52
53
|
# File 'lib/dwc_archive.rb', line 51
def archive
@archive
end
|
#classification_normalizer ⇒ Object
Returns the value of attribute classification_normalizer.
51
52
53
|
# File 'lib/dwc_archive.rb', line 51
def classification_normalizer
@classification_normalizer
end
|
#core ⇒ Object
Returns the value of attribute core.
51
52
53
|
# File 'lib/dwc_archive.rb', line 51
def core
@core
end
|
Returns the value of attribute metadata.
51
52
53
|
# File 'lib/dwc_archive.rb', line 51
def metadata
@metadata
end
|
Class Method Details
.clean(path) ⇒ Object
36
37
38
|
# 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) ⇒ Object
60
61
62
63
64
65
|
# 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) ⇒ Object
40
41
42
43
44
|
# 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_reset ⇒ Object
71
72
73
|
# File 'lib/dwc_archive.rb', line 71
def self.logger_reset
self.logger = Logger.new(nil)
end
|
.logger_write(obj_id, message, method = :info) ⇒ Object
75
76
77
|
# File 'lib/dwc_archive.rb', line 75
def self.logger_write(obj_id, message, method = :info)
logger.send(method, "|#{obj_id}|#{message}|")
end
|
.nil_field?(field) ⇒ Boolean
54
55
56
57
58
|
# 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) ⇒ Object
46
47
48
|
# File 'lib/dwc_archive.rb', line 46
def random_path(tmp_dir)
File.join(tmp_dir, "dwc_#{rand(10_000_000_000)}")
end
|
Instance Method Details
#checksum ⇒ Object
110
111
112
|
# File 'lib/dwc_archive.rb', line 110
def checksum
Digest::SHA1.hexdigest(File.read(@dwc_path))
end
|
#extensions ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# 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 ⇒ Object
87
88
89
|
# File 'lib/dwc_archive.rb', line 87
def file_name
File.split(@dwc_path).last
end
|
#normalize_classification ⇒ Object
generates a hash from a classification data with path to each node, list of synonyms and vernacular names.
97
98
99
100
101
102
103
|
# 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? ⇒ Boolean
105
106
107
108
|
# File 'lib/dwc_archive.rb', line 105
def parent_id?
!@core.fields.join("|").
downcase.match(/highertaxonid|parentnameusageid/).nil?
end
|
#path ⇒ Object
91
92
93
|
# File 'lib/dwc_archive.rb', line 91
def path
File.expand_path(@dwc_path)
end
|