Class: CollectionObjectObservation

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Depictions, Shared::IsData, Shared::Notable, Shared::Taggable
Defined in:
app/models/collection_object_observation.rb

Overview

A special purpose notes field that records the notes of someone observing one or more collection objects.

Includes verbatim block of text (perhaps json too ultimately) that details observations on a collection object. Should only include notes on CollectionObjects, not field observations, i.e. this is a precursor of a CollectionObject instance.

Example usages: 1) Recording notes metadata about a image that contains multiple slides or non-emunmarated collection objects 2) While working in a collection a user rapidly types all labels/metadata from a specimen into one field, and moves on. This data is later broken down into individual records

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) data

TODO:

Returns:

  • (String)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/collection_object_observation.rb', line 19

class CollectionObjectObservation < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::Taggable
  include Shared::Notable
  include Shared::Depictions

  has_many :derived_collection_objects, inverse_of: :collection_object_observations
  has_many :collection_objects, through: :derived_collection_objects

  validates_presence_of :data

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    where('data LIKE ? OR data ILIKE ? OR data = ?', term, "#{term}%", "%term").where(project_id: params[:project_id])
  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

end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/collection_object_observation.rb', line 19

class CollectionObjectObservation < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::Taggable
  include Shared::Notable
  include Shared::Depictions

  has_many :derived_collection_objects, inverse_of: :collection_object_observations
  has_many :collection_objects, through: :derived_collection_objects

  validates_presence_of :data

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    where('data LIKE ? OR data ILIKE ? OR data = ?', term, "#{term}%", "%term").where(project_id: params[:project_id])
  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

end

Class Method Details

+ (Object) find_for_autocomplete(params)



31
32
33
34
# File 'app/models/collection_object_observation.rb', line 31

def self.find_for_autocomplete(params)
  term = "#{params[:term]}%"
  where('data LIKE ? OR data ILIKE ? OR data = ?', term, "#{term}%", "%term").where(project_id: params[:project_id])
end

+ (Object) generate_download(scope)



36
37
38
39
40
41
42
43
44
45
# File 'app/models/collection_object_observation.rb', line 36

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