lib/dwc-archive.rb in dwc-archive-0.9.6 vs lib/dwc-archive.rb in dwc-archive-0.9.10

- old
+ new

@@ -1,36 +1,38 @@ # encoding: UTF-8 -$:.unshift(File.dirname(__FILE__)) unless - $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) -R19 = RUBY_VERSION.split('.')[0..1].join('').to_i > 18 -raise "IMPORTANT: dwc-archive gem requires ruby >= 1.9.1" unless R19 + +recent_ruby = RUBY_VERSION >= '1.9.1' +raise "IMPORTANT: dwc-archive gem requires ruby >= 1.9.1" unless recent_ruby + require 'fileutils' require 'ostruct' require 'digest' require 'csv' require 'logger' -require 'dwc-archive/xml_reader' -require 'dwc-archive/ingester' -require 'dwc-archive/errors' -require 'dwc-archive/expander' -require 'dwc-archive/archive' -require 'dwc-archive/core' -require 'dwc-archive/extension' -require 'dwc-archive/metadata' -require 'dwc-archive/generator' -require 'dwc-archive/generator_meta_xml' -require 'dwc-archive/generator_eml_xml' -require 'dwc-archive/classification_normalizer' +require_relative 'dwc-archive/xml_reader' +require_relative 'dwc-archive/ingester' +require_relative 'dwc-archive/errors' +require_relative 'dwc-archive/expander' +require_relative 'dwc-archive/archive' +require_relative 'dwc-archive/core' +require_relative 'dwc-archive/extension' +require_relative 'dwc-archive/metadata' +require_relative 'dwc-archive/generator' +require_relative 'dwc-archive/generator_meta_xml' +require_relative 'dwc-archive/generator_eml_xml' +require_relative 'dwc-archive/classification_normalizer' +require_relative 'dwc-archive/version' class DarwinCore - VERSION = open(File.join(File.dirname(__FILE__), '..', 'VERSION')).readline.strip + VERSION = DarwinCore::VERSION + DEFAULT_TMP_DIR = "/tmp" - attr_reader :archive, :core, :metadata, :extensions, :classification_normalizer + attr_reader :archive, :core, :metadata, :extensions, + :classification_normalizer alias :eml :metadata - DEFAULT_TMP_DIR = "/tmp" def self.nil_field?(field) return true if [nil, '', '/N'].include?(field) false end @@ -66,13 +68,23 @@ @core = DarwinCore::Core.new(self) @metadata = DarwinCore::Metadata.new(@archive) @extensions = get_extensions end - # generates a hash from a classification data with path to each node, list of synonyms and vernacular names. + def file_name + File.split(@dwc_path).last + end + + def path + File.expand_path(@dwc_path) + end + + # generates a hash from a classification data with path to each node, + # list of synonyms and vernacular names. def normalize_classification return nil unless has_parent_id? - @classification_normalizer ||= DarwinCore::ClassificationNormalizer.new(self) + @classification_normalizer ||= DarwinCore::ClassificationNormalizer. + new(self) @classification_normalizer.normalize end def has_parent_id? !!@core.fields.join('|').downcase.match(/highertaxonid|parentnameusageid/)