Module: Shared::DataAttributes

Overview

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

Instance Method Summary collapse

Instance Method Details

#import_attributesScope

Returns:

  • (Scope)


21
22
23
# File 'app/models/concerns/shared/data_attributes.rb', line 21

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

#internal_attributesScope

Returns:

  • (Scope)


16
17
18
# File 'app/models/concerns/shared/data_attributes.rb', line 16

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

#keyword_value_hashHash

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

Returns:

  • (Hash)

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



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

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



38
39
40
# File 'app/models/concerns/shared/data_attributes.rb', line 38

def reject_data_attributes(attributed)
  attributed['value'].blank? || attributed['type'].blank?
end