Class: Descriptor

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::AlternateValues, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::Documentation, Shared::Identifiers, Shared::IsData, Shared::Notes, Shared::Tags, SoftValidation
Defined in:
app/models/descriptor.rb

Overview

Descriptors are the general mechanism for describing CollectionObjects (individual specimens) or Otus (taxa).

They come in various types, reflecting the approaches commonly used to describe specimens and OTUs:

Working - raw notes or images, "primal" observations, not yet refined to states or measurements
Qualitative - Represents character/character_state expressions as traditionally understood.
Quantitative - Single measurements.
Sample - Summaries of multiple observations recorded in a statistical manner. Only valid for Otus. For example "length 42-77mm (n=5, min: 42, max:Only valid for Otus."

Defined Under Namespace

Classes: Autocomplete, Continuous, Gene, Media, PresenceAbsence, Qualitative, Sample, Working

Constant Summary collapse

ALTERNATE_VALUES_FOR =
[:name, :short_name].freeze

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SoftValidation

#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Class Method Details

.human_nameObject



40
41
42
# File 'app/models/descriptor.rb', line 40

def self.human_name
  self.name.demodulize.humanize
end

Instance Method Details

#gene?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/descriptor.rb', line 52

def gene?
  type == 'Descriptor::Gene'
end

#presence_absence?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/descriptor.rb', line 48

def presence_absence?
  type == 'Descriptor::PresenceAbsence'
end

#qualitative?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/descriptor.rb', line 44

def qualitative?
  type == 'Descriptor::Qualitative'
end

#short_name_is_shorterObject (protected)



64
65
66
# File 'app/models/descriptor.rb', line 64

def short_name_is_shorter
  errors.add(:short_name, 'is longer than name!') if short_name && name && (short_name.length > name.length)
end

#sv_short_name_is_shortObject (protected)



68
69
70
# File 'app/models/descriptor.rb', line 68

def sv_short_name_is_short
  soft_validations.add(:short_name, 'should likely be less than 12 characters long') if short_name && short_name.length > 12
end

#type_is_subclassedObject (protected)



58
59
60
61
62
# File 'app/models/descriptor.rb', line 58

def type_is_subclassed
  if !DESCRIPTOR_TYPES[type]
    errors.add(:type, 'type must be a valid subclass')
  end
end