Class: DataAttribute

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, 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.

DataAttribute is only instantiated through its subclasses ImportAttribute or InternalAttribute

Direct Known Subclasses

ImportAttribute, InternalAttribute

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (Integer) attribute_subject_id

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
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject')

  # Please DO NOT include the following:  (follows Identifier approach)
  #   validates_presence_of :attribute_subject_type, :attribute_subject_id
  #   validates :attribute_subject, presence: true
  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]
  #   then predicate name
  def predicate_name
    type == 'InternalAttribute' ? predicate.name : import_predicate
  end

end

- (String) attribute_subject_type

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
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject')

  # Please DO NOT include the following:  (follows Identifier approach)
  #   validates_presence_of :attribute_subject_type, :attribute_subject_id
  #   validates :attribute_subject, presence: true
  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]
  #   then predicate name
  def predicate_name
    type == 'InternalAttribute' ? predicate.name : import_predicate
  end

end

- (Integer) controlled_vocabulary_term_id

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
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject')

  # Please DO NOT include the following:  (follows Identifier approach)
  #   validates_presence_of :attribute_subject_type, :attribute_subject_id
  #   validates :attribute_subject, presence: true
  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]
  #   then predicate name
  def predicate_name
    type == 'InternalAttribute' ? predicate.name : import_predicate
  end

end

- (Integer) project_id

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
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject')

  # Please DO NOT include the following:  (follows Identifier approach)
  #   validates_presence_of :attribute_subject_type, :attribute_subject_id
  #   validates :attribute_subject, presence: true
  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]
  #   then predicate name
  def predicate_name
    type == 'InternalAttribute' ? predicate.name : import_predicate
  end

end

- (String) type

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
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject')

  # Please DO NOT include the following:  (follows Identifier approach)
  #   validates_presence_of :attribute_subject_type, :attribute_subject_id
  #   validates :attribute_subject, presence: true
  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]
  #   then predicate name
  def predicate_name
    type == 'InternalAttribute' ? predicate.name : import_predicate
  end

end

- (String) value

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
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('attribute_subject')

  # Please DO NOT include the following:  (follows Identifier approach)
  #   validates_presence_of :attribute_subject_type, :attribute_subject_id
  #   validates :attribute_subject, presence: true
  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]
  #   then predicate name
  def predicate_name
    type == 'InternalAttribute' ? predicate.name : import_predicate
  end

end

Class Method Details

+ (Object) find_for_autocomplete(params)

Needs to extend to predicate/value searches



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

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

Instance Method Details

- (Boolean) editable?

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

Returns:

  • (Boolean)

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



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

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

- (String) predicate_name

Returns then predicate name

Returns:

  • (String)

    then predicate name



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

def predicate_name
  type == 'InternalAttribute' ? predicate.name : import_predicate
end