Class: Observation

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::Depictions, Shared::Identifiers, Shared::IsData, Shared::Notes, Shared::Tags
Defined in:
app/models/observation.rb

Overview

Observations are of various types, e.g. Qualitative, Quantitative, Statistical. Made on an Otu or CollectionObject. They are where you store the data for concepts like traits, phenotypes, measurements, character matrices, descriptive matrices etc.

Direct Known Subclasses

Continuous, Media, PresenceAbsence, Qualitative, Sample, Working

Defined Under Namespace

Classes: Continuous, Media, PresenceAbsence, Qualitative, Sample, Working

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Attribute Details

- (Object) observation_object_global_id

Returns the value of attribute observation_object_global_id



17
18
19
# File 'app/models/observation.rb', line 17

def observation_object_global_id
  @observation_object_global_id
end

Class Method Details

+ (Boolean) copy(old_global_id, new_global_id)

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/observation.rb', line 74

def self.copy(old_global_id, new_global_id)
  begin
    old = GlobalID::Locator.locate(old_global_id)

    Observation.transaction do
      old.observations.each do |o|
        d = o.dup
        d.update(observation_object_global_id: new_global_id) 
      end
    end
    true
  rescue
    return false
  end
  true
end

+ (Object) destroy_row(observation_matrix_row_id)

Remove all observations for the set of descriptors in a given row



92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/observation.rb', line 92

def self.destroy_row(observation_matrix_row_id)
  r = ObservationMatrixRow.find(observation_matrix_row_id)
  begin
    Observation.transaction do
      r.observations.destroy_all
    end
  rescue
    raise
  end
  true
end

+ (Object) human_name



35
36
37
# File 'app/models/observation.rb', line 35

def self.human_name
  'YAY'
end

+ (Object) object_scope(object)



28
29
30
31
32
33
# File 'app/models/observation.rb', line 28

def self.object_scope(object)
  return Observation.none if object.nil?
  return Observation.where(otu_id: object.id) if object.class.name == 'Otu'
  return Observation.where(collection_object_id: object.id) if object.metamorphosize.class.name == 'CollectionObject'
  Observation.none 
end

Instance Method Details

- (Object) convert_observation_object_global_id (protected)



106
107
108
# File 'app/models/observation.rb', line 106

def convert_observation_object_global_id
  set_observation_object_id(GlobalID::Locator.locate(observation_object_global_id)) if observation_object_global_id 
end

- (Object) observation_object



39
40
41
# File 'app/models/observation.rb', line 39

def observation_object
  [otu, collection_object].compact.first
end

- (Object) otu_or_collection_object_set (protected)



110
111
112
113
114
# File 'app/models/observation.rb', line 110

def otu_or_collection_object_set
  if otu_id.blank? && collection_object_id.blank? && otu.blank? && collection_object.blank?
    errors.add(:base, 'observations must reference an Otu or collection object')
  end
end

- (Object) set_observation_object_id(object)



48
49
50
51
52
53
54
55
56
57
# File 'app/models/observation.rb', line 48

def set_observation_object_id(object)
  case object.metamorphosize.class.name
  when 'Otu'
    write_attribute(:otu_id, object.id)
  when 'CollectionObject'
    write_attribute(:collection_object_id, object.id)
  else
    return false
  end 
end