Module: Shared::AlternateValues

Extended by:
ActiveSupport::Concern
Included in:
CharacterState, CommonName, ControlledVocabularyTerm, Descriptor, GeographicArea, ObservationMatrix, Person, Repository, Sequence, Serial, Source, TaxonName
Defined in:
app/models/concerns/shared/alternate_values.rb

Overview

Shared code for providing alternate values for individual columns.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#all_values_for(attr) ⇒ Array

Returns a sorted Array of associated values eg. returns self.name from otu.all_values_for(name).

Parameters:

  • attr (Symbol)

Returns:

  • (Array)

    a sorted Array of associated values eg. returns self.name from otu.all_values_for(name)



25
26
27
28
29
30
31
32
33
# File 'app/models/concerns/shared/alternate_values.rb', line 25

def all_values_for(attr)
  values = [self.send(attr)]
  if alternate_valued?
    alternate_values.each do |v|
      values.push(v.value) if v.alternate_value_object_attribute == attr.to_s
    end
  end
  return values.sort
end

#alternate_valued?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/models/concerns/shared/alternate_values.rb', line 17

def alternate_valued?
  self.alternate_values.any?
end