Class: DarwinCore
- Inherits:
-
Object
- Object
- DarwinCore
- 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
-
#archive ⇒ Object
readonly
Returns the value of attribute archive.
-
#classification_normalizer ⇒ Object
readonly
Returns the value of attribute classification_normalizer.
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#metadata ⇒ Object
(also: #eml)
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
- .clean_all(tmp_dir = DEFAULT_TMP_DIR) ⇒ Object
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
- .logger_reset ⇒ Object
- .logger_write(obj_id, message, method = :info) ⇒ Object
- .nil_field?(field) ⇒ Boolean
Instance Method Summary collapse
- #checksum ⇒ Object
- #has_parent_id? ⇒ Boolean
-
#initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR) ⇒ DarwinCore
constructor
A new instance of DarwinCore.
-
#normalize_classification ⇒ Object
generates a hash from a classification data with path to each node, list of synonyms and vernacular names.
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
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
28 29 30 |
# File 'lib/dwc-archive.rb', line 28 def archive @archive end |
#classification_normalizer ⇒ Object (readonly)
Returns the value of attribute classification_normalizer.
28 29 30 |
# File 'lib/dwc-archive.rb', line 28 def classification_normalizer @classification_normalizer end |
#core ⇒ Object (readonly)
Returns the value of attribute core.
28 29 30 |
# File 'lib/dwc-archive.rb', line 28 def core @core end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
28 29 30 |
# File 'lib/dwc-archive.rb', line 28 def extensions @extensions end |
#metadata ⇒ Object (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 |
.logger ⇒ Object
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_reset ⇒ Object
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, , method = :info) self.logger.send(method, "|%s|%s|" % [obj_id, ]) end |
.nil_field?(field) ⇒ 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
#checksum ⇒ Object
82 83 84 |
# File 'lib/dwc-archive.rb', line 82 def checksum Digest::SHA1.hexdigest(open(@dwc_path).read) end |
#has_parent_id? ⇒ Boolean
78 79 80 |
# File 'lib/dwc-archive.rb', line 78 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.
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 |