Module: Shared::AlternateValues

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

- (Object) all_values_for(attr)

returns a sorted Array of associated values

Parameters:

  • attr (Symbol)


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

def all_values_for(attr)
  # eg. returns self.name from otu.all_values_for(name)
  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)


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

def alternate_valued?
  self.alternate_values.any?
end