Module: Shared::DataAttributes

Extended by:
ActiveSupport::Concern
Included in:
AssertedDistribution, BiologicalAssociation, BiologicalRelationship, CharacterState, Citation, CollectingEvent, CollectionObject, CommonName, Descriptor, Loan, LoanItem, Observation, ObservationMatrix, Otu, Person, Sequence, Serial, Source, TaxonName, TypeMaterial, User
Defined in:
app/models/concerns/shared/data_attributes.rb

Overview

Shared code extending data classes with data-attributes (predicate->value tags).

Instance Method Summary (collapse)

Instance Method Details

- (Scope) import_attributes

Returns:

  • (Scope)


19
20
21
# File 'app/models/concerns/shared/data_attributes.rb', line 19

def import_attributes
  data_attributes.where(type: 'ImportAttribute')
end

- (Scope) internal_attributes

Returns:

  • (Scope)


14
15
16
# File 'app/models/concerns/shared/data_attributes.rb', line 14

def internal_attributes
  data_attributes.where(type: 'InternalAttribute')
end

- (Hash) keyword_value_hash

Returns all data attributes in String (name) -> value format

Returns:

  • (Hash)

    all data attributes in String (name) -> value format



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

def keyword_value_hash
  self.data_attributes.inject({}) do |hsh, a|
    if a.kind_of?(ImportAttribute)
      hsh[a.import_predicate] = a.value
    else # If not an ImportAttribute then it's an InternalAttribute
      hsh[a.predicate.name] = a.value
    end
    hsh
  end
end