Class: ObservationMatrixRow

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Class Method Details

+ (Object) sort(array)

Returns true incrementally sort the supplied ids

Parameters:

  • array (Array)

Returns:

  • true incrementally sort the supplied ids



27
28
29
30
31
32
# File 'app/models/observation_matrix_row.rb', line 27

def self.sort(array)
  array.each_with_index do |id, index|
    ObservationMatrixRow.where(id: id).update_all(position: index + 1) 
  end
  true
end

Instance Method Details

- (Object) next_row



46
47
48
# File 'app/models/observation_matrix_row.rb', line 46

def next_row
  observation_matrix.observation_matrix_rows.where("position > ?", position).order(:position).first 
end

- (Object) otu_and_collection_object_blank (private)



56
57
58
59
60
# File 'app/models/observation_matrix_row.rb', line 56

def otu_and_collection_object_blank
  if otu_id.nil? && collection_object_id.nil?
    errors.add(:base, 'Specify otu OR collection object!')
  end
end

- (Object) otu_and_collection_object_given (private)



62
63
64
65
66
# File 'app/models/observation_matrix_row.rb', line 62

def otu_and_collection_object_given
  if !otu_id.nil? && !collection_object_id.nil?
    errors.add(:base, 'Specify otu OR collection object, not both!')
  end
end

- (Object) previous_row



50
51
52
# File 'app/models/observation_matrix_row.rb', line 50

def previous_row
  observation_matrix.observation_matrix_rows.where("position < ?", position).order('position DESC').first 
end

- (Object) row_object



38
39
40
# File 'app/models/observation_matrix_row.rb', line 38

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

- (Object) row_object_class_name



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

def row_object_class_name
  row_object.class.name
end

- (Object) set_reference_count



34
35
36
# File 'app/models/observation_matrix_row.rb', line 34

def set_reference_count
  self.reference_count ||= 0
end