Class: DarwinCore
- Inherits:
-
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
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.
Instance Attribute Details
#archive ⇒ Object
Returns the value of attribute archive.
30
31
32
|
# File 'lib/dwc-archive.rb', line 30
def archive
@archive
end
|
#classification_normalizer ⇒ Object
Returns the value of attribute classification_normalizer.
30
31
32
|
# File 'lib/dwc-archive.rb', line 30
def classification_normalizer
@classification_normalizer
end
|
#core ⇒ Object
Returns the value of attribute core.
30
31
32
|
# File 'lib/dwc-archive.rb', line 30
def core
@core
end
|
#extensions ⇒ Object
Returns the value of attribute extensions.
30
31
32
|
# File 'lib/dwc-archive.rb', line 30
def extensions
@extensions
end
|
Returns the value of attribute metadata.
30
31
32
|
# File 'lib/dwc-archive.rb', line 30
def metadata
@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
|
.logger ⇒ Object
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_reset ⇒ Object
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
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
#checksum ⇒ Object
94
95
96
|
# File 'lib/dwc-archive.rb', line 94
def checksum
Digest::SHA1.hexdigest(open(@dwc_path).read)
end
|
#file_name ⇒ Object
73
74
75
|
# File 'lib/dwc-archive.rb', line 73
def file_name
File.split(@dwc_path).last
end
|
#has_parent_id? ⇒ Boolean
90
91
92
|
# File 'lib/dwc-archive.rb', line 90
def has_parent_id?
!!@core.fields.join('|').downcase.match(/highertaxonid|parentnameusageid/)
end
|
#normalize_classification ⇒ Object
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
|
#path ⇒ Object
77
78
79
|
# File 'lib/dwc-archive.rb', line 77
def path
File.expand_path(@dwc_path)
end
|