lib/dwc-archive/classification_normalizer.rb in dwc-archive-0.7.18 vs lib/dwc-archive/classification_normalizer.rb in dwc-archive-0.8.0

- old
+ new

@@ -2,11 +2,11 @@ require 'parsley-store' class DarwinCore class TaxonNormalized - attr_accessor :id, :local_id, :global_id, :source, :parent_id, :classification_path_id, :classification_path, :current_name, :current_name_canonical, :synonyms, :vernacular_names, :rank, :status + attr_accessor :id, :local_id, :global_id, :source, :parent_id, :classification_path_id, :classification_path, :linnean_classification_path, :current_name, :current_name_canonical, :synonyms, :vernacular_names, :rank, :status def initialize @id = @parent_id = @rank = @status = nil @current_name = '' @current_name_canonical = '' @@ -15,10 +15,11 @@ @global_id = '' @classification_path = [] @classification_path_id = [] @synonyms = [] @vernacular_names = [] + @linnean_classification_path = [] end end class SynonymNormalized < Struct.new(:id, :name, :canonical_name, :status, :source, :local_id, :global_id);end @@ -163,10 +164,11 @@ taxon.parent_id = has_parent_id? ? r[parent_id] : nil taxon.rank = r[@core_fields[:taxonrank]] if @core_fields[:taxonrank] taxon.status = r[@core_fields[:taxonomicstatus]] if @core_fields[:taxonomicstatus] taxon.source = r[@core_fields[:source]] if @core_fields[:source] taxon.local_id = r[@core_fields[:localid]] if @core_fields[:localid] + taxon.linnean_classification_path = get_linnean_classification_path(r) taxon.global_id = r[@core_fields[:globalid]] if @core_fields[:globalid] add_name_string(taxon.current_name) add_name_string(taxon.current_name_canonical) if taxon.current_name_canonical && !taxon.current_name_canonical.empty? end end @@ -308,9 +310,17 @@ else @error_names << { :vernacular_name => vernacular, :error => :vernacular_of_unknown_taxa } end end end + end + + def get_linnean_classification_path(row) + res = [] + [:kingdom, :phylum, :class, :order, :family, :genus, :subgenus].each do |clade| + res << [row[@core_fields[clade]], clade] if @core_fields[clade] + end + res end end end