Class: DataAttribute

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Housekeeping, Shared::DualAnnotator, Shared::IsData
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?

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::DualAnnotator

  belongs_to :attribute_subject, polymorphic: true

  # 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 [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    attribute_subject
  end

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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::DualAnnotator

  belongs_to :attribute_subject, polymorphic: true

  # 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 [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    attribute_subject
  end

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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::DualAnnotator

  belongs_to :attribute_subject, polymorphic: true

  # 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 [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    attribute_subject
  end

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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::DualAnnotator

  belongs_to :attribute_subject, polymorphic: true

  # 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 [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    attribute_subject
  end

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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::DualAnnotator

  belongs_to :attribute_subject, polymorphic: true

  # 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 [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    attribute_subject
  end

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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/data_attribute.rb', line 29

class DataAttribute < ActiveRecord::Base
  include Housekeeping
  include Shared::IsData 
  include Shared::DualAnnotator

  belongs_to :attribute_subject, polymorphic: true

  # 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 [NoteObject]
  #   alias to simplify reference across classes 
  def annotated_object
    attribute_subject
  end

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

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  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

+ (Object) generate_download(scope)



58
59
60
61
62
63
64
65
66
67
# File 'app/models/data_attribute.rb', line 58

def self.generate_download(scope)
  CSV.generate do |csv|
    csv << column_names
    scope.order(id: :asc).each do |o|
      csv << o.attributes.values_at(*column_names).collect { |i|
        i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
      }
    end
  end
end

Instance Method Details

- (NoteObject) annotated_object

Returns alias to simplify reference across classes

Returns:

  • (NoteObject)

    alias to simplify reference across classes



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

def annotated_object
  attribute_subject
end

- (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



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

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

- (String) predicate_name

Returns then predicate name

Returns:

  • (String)

    then predicate name



71
72
73
# File 'app/models/data_attribute.rb', line 71

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