Module: Shared::Taxonomy

Extended by:
ActiveSupport::Concern
Included in:
AnatomicalPart, AssertedDistribution, CollectionObject, FieldOccurrence, Otu
Defined in:
app/models/concerns/shared/taxonomy.rb

Overview

Conceptually there are 2 aspects of building @taxonomy 1) The higher, monomial names 2) The elements of the scientificNamm.

Instance Method Summary collapse

Instance Method Details

#taxonomy_for_object(o) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/models/concerns/shared/taxonomy.rb', line 100

def taxonomy_for_object(o)
  case o.class.base_class.name
  when 'CollectionObject', 'FieldOccurrence'
    a = o.target_taxon_name # current_valid_taxon_name # !! See DwcExtensions, probably better placed here

    # If we have no name, see if there is a Type reference and use it as proxy
    # !! Careful/TODO this is an arbitrary choice, technically can be only one primary, but not restricted in DB yet
    if o.class.base_class.name == 'CollectionObject'
      a ||= o.type_materials.primary.first&.protonym
    end
  when 'Otu'
    if o.taxon_name
      if o.taxon_name.cached_is_valid
        o.taxon_name
      else
        o.taxon_name.valid_taxon_name
      end
    end

  when 'AssertedDistribution'

    # TODO: this is faster, but needs spec confirmation
    # Benchmark.measure { 2000.times do;  AssertedDistribution.find_by_id(ids.sample).taxonomy; end;  }
    #
    # TaxonName.joins('JOIN taxon_names tn on tn.id = taxon_names.cached_valid_taxon_name_id')
    #   .joins('JOIN otus o on o.taxon_name_id = tn.id')
    #   .where(o: { id: otu_id })
    #   .first

    o.otu&.taxon_name&.valid_taxon_name

  when 'AnatomicalPart'
    o.origin_otu.taxon_name

  when 'TaxonName' # not used (probably has to be subclassed)
    o
  end
end