Module: Shared::AlternateValues

Extended by:
ActiveSupport::Concern
Included in:
CharacterState, CommonName, ControlledVocabularyTerm, Descriptor, Person, 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

- (Array) all_values_for(attr)

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)



19
20
21
22
23
24
25
26
27
# File 'app/models/concerns/shared/alternate_values.rb', line 19

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

- (Boolean) alternate_valued?

Returns:

  • (Boolean)


11
12
13
# File 'app/models/concerns/shared/alternate_values.rb', line 11

def alternate_valued?
  self.alternate_values.any?
end