Module: Shared::DataAttributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- AssertedDistribution, BiologicalAssociation, BiologicalRelationship, CharacterState, CollectingEvent, CollectionObject, CommonName, Content, Depiction, Descriptor, Extract, FieldOccurrence, Georeference, Loan, LoanItem, Observation, ObservationMatrix, Otu, Person, Repository, Sequence, Serial, Source, TaxonDetermination, 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
- #import_attributes ⇒ Scope
- #internal_attributes ⇒ Scope
-
#keyword_value_hash ⇒ Hash
All data attributes in String (name) -> value format.
- #reject_data_attributes(attributed) ⇒ Object
Instance Method Details
#import_attributes ⇒ Scope
25 26 27 |
# File 'app/models/concerns/shared/data_attributes.rb', line 25 def import_attributes data_attributes.where(type: 'ImportAttribute') end |
#internal_attributes ⇒ Scope
20 21 22 |
# File 'app/models/concerns/shared/data_attributes.rb', line 20 def internal_attributes data_attributes.where(type: 'InternalAttribute') end |
#keyword_value_hash ⇒ Hash
Returns all data attributes in String (name) -> value format.
31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/concerns/shared/data_attributes.rb', line 31 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 |
#reject_data_attributes(attributed) ⇒ Object
42 43 44 |
# File 'app/models/concerns/shared/data_attributes.rb', line 42 def reject_data_attributes(attributed) attributed['value'].blank? || attributed['type'].blank? end |