Class: DataAttribute

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Citations, Shared::DualAnnotator, Shared::IsData, Shared::PolymorphicAnnotator
Defined in:
app/models/data_attribute.rb

Overview

A data attribute is used to attach an arbitrary predicate/literal pair to a data instance, essentially creating a user-defined triple. It is the primary mechanism of extending data-models in TaxonWorks.

A DataAttribute is only instantiated through its subclasses ImportAttribute or InternalAttribute

Direct Known Subclasses

ImportAttribute, InternalAttribute

Constant Summary

Constants included from Shared::DualAnnotator

Shared::DualAnnotator::ALWAYS_COMMUNITY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared::PolymorphicAnnotator

#annotated_object_is_persisted?

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Citations

#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#attribute_subject_idInteger

The id of the subject (Rails polymorphic relationship).

Returns:

  • (Integer)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::Citations
  include Shared::DualAnnotator
  # include Shared::Protocol
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject', inverse_of: :data_attributes)

  belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes

  validates_presence_of :type, :value

  # Needs to extend to predicate/value searches
  def self.find_for_autocomplete(params)
    where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  end

  # @return [Boolean]
  #   true if value can be edited, i.e. an InternalAttribute
  def editable?
    self.type == 'InternalAttribute'
  end

  # @return [String]
  #   the predicate name
  def predicate_name
    # type == 'InternalAttribute' ? predicate.name : import_predicate
    type.start_with?('Im') ? import_predicate : predicate.name
  end


end

#attribute_subject_typeString

The class of the subject (Rails polymorphic relationship).

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::Citations
  include Shared::DualAnnotator
  # include Shared::Protocol
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject', inverse_of: :data_attributes)

  belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes

  validates_presence_of :type, :value

  # Needs to extend to predicate/value searches
  def self.find_for_autocomplete(params)
    where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  end

  # @return [Boolean]
  #   true if value can be edited, i.e. an InternalAttribute
  def editable?
    self.type == 'InternalAttribute'
  end

  # @return [String]
  #   the predicate name
  def predicate_name
    # type == 'InternalAttribute' ? predicate.name : import_predicate
    type.start_with?('Im') ? import_predicate : predicate.name
  end


end

#controlled_vocabulary_term_idInteger

Returns Id of the Predicate for InternalAttributes.

Returns:

  • (Integer)

    Id of the Predicate for InternalAttributes



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::Citations
  include Shared::DualAnnotator
  # include Shared::Protocol
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject', inverse_of: :data_attributes)

  belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes

  validates_presence_of :type, :value

  # Needs to extend to predicate/value searches
  def self.find_for_autocomplete(params)
    where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  end

  # @return [Boolean]
  #   true if value can be edited, i.e. an InternalAttribute
  def editable?
    self.type == 'InternalAttribute'
  end

  # @return [String]
  #   the predicate name
  def predicate_name
    # type == 'InternalAttribute' ? predicate.name : import_predicate
    type.start_with?('Im') ? import_predicate : predicate.name
  end


end

#project_idInteger

the project ID

Returns:

  • (Integer)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::Citations
  include Shared::DualAnnotator
  # include Shared::Protocol
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject', inverse_of: :data_attributes)

  belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes

  validates_presence_of :type, :value

  # Needs to extend to predicate/value searches
  def self.find_for_autocomplete(params)
    where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  end

  # @return [Boolean]
  #   true if value can be edited, i.e. an InternalAttribute
  def editable?
    self.type == 'InternalAttribute'
  end

  # @return [String]
  #   the predicate name
  def predicate_name
    # type == 'InternalAttribute' ? predicate.name : import_predicate
    type.start_with?('Im') ? import_predicate : predicate.name
  end


end

#typeString

The type of DataAttribute (Rails STI).

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::Citations
  include Shared::DualAnnotator
  # include Shared::Protocol
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject', inverse_of: :data_attributes)

  belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes

  validates_presence_of :type, :value

  # Needs to extend to predicate/value searches
  def self.find_for_autocomplete(params)
    where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  end

  # @return [Boolean]
  #   true if value can be edited, i.e. an InternalAttribute
  def editable?
    self.type == 'InternalAttribute'
  end

  # @return [String]
  #   the predicate name
  def predicate_name
    # type == 'InternalAttribute' ? predicate.name : import_predicate
    type.start_with?('Im') ? import_predicate : predicate.name
  end


end

#valueString

The user provided data, e.g., RFD literal or object, i.e. RDF literal, i.e. data in a cell of a spreadsheet. Always required.

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::Citations
  include Shared::DualAnnotator
  # include Shared::Protocol
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject', inverse_of: :data_attributes)

  belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes

  validates_presence_of :type, :value

  # Needs to extend to predicate/value searches
  def self.find_for_autocomplete(params)
    where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
  end

  # @return [Boolean]
  #   true if value can be edited, i.e. an InternalAttribute
  def editable?
    self.type == 'InternalAttribute'
  end

  # @return [String]
  #   the predicate name
  def predicate_name
    # type == 'InternalAttribute' ? predicate.name : import_predicate
    type.start_with?('Im') ? import_predicate : predicate.name
  end


end

Class Method Details

.find_for_autocomplete(params) ⇒ Object

Needs to extend to predicate/value searches



43
44
45
# File 'app/models/data_attribute.rb', line 43

def self.find_for_autocomplete(params)
  where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id])
end

Instance Method Details

#editable?Boolean

Returns true if value can be edited, i.e. an InternalAttribute.

Returns:

  • (Boolean)

    true if value can be edited, i.e. an InternalAttribute



49
50
51
# File 'app/models/data_attribute.rb', line 49

def editable?
  self.type == 'InternalAttribute'
end

#predicate_nameString

Returns the predicate name.

Returns:

  • (String)

    the predicate name



55
56
57
58
# File 'app/models/data_attribute.rb', line 55

def predicate_name
  # type == 'InternalAttribute' ? predicate.name : import_predicate
  type.start_with?('Im') ? import_predicate : predicate.name
end