Class: ObservationMatrixColumn

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

Overview

An ObservationMatrixColumn defines the column in an observation matrix. ObservationMatrixColumn items are only created and destroyed through references to ObservationMatrixColumnItems, never directly!

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Notes

#concatenated_notes_string, #reject_notes

Methods included from Shared::Tags

#reject_tags, #tag_with, #tagged?, #tagged_with?

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#cached_observation_matrix_column_item_idInteger

Returns if the reference_count is 1, and the presence of this column is here because of reference to a /Single/ ObservationMatrixColumnItem column, then cache the ID of that column.

Returns:

  • (Integer)

    if the reference_count is 1, and the presence of this column is here because of reference to a /Single/ ObservationMatrixColumnItem column, then cache the ID of that column



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/observation_matrix_column.rb', line 23

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::Notes
  include Shared::IsData

  acts_as_list scope: [:observation_matrix_id, :project_id]

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  after_initialize :set_reference_count

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @return Scope
  #  There is no order to these Observations!  They do not follow the row order.
  def observations
    Observation.in_observation_matrix(observation_matrix_id).where(descriptor_id: descriptor_id)
  end

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  # TODO: belong in helpers
  def next_column
    observation_matrix.observation_matrix_columns.where("position > ?", position).order(:position).first
  end

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

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

#descriptor_idInteger

Returns the descriptor in the column.

Returns:

  • (Integer)

    the descriptor in the column



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/observation_matrix_column.rb', line 23

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::Notes
  include Shared::IsData

  acts_as_list scope: [:observation_matrix_id, :project_id]

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  after_initialize :set_reference_count

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @return Scope
  #  There is no order to these Observations!  They do not follow the row order.
  def observations
    Observation.in_observation_matrix(observation_matrix_id).where(descriptor_id: descriptor_id)
  end

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  # TODO: belong in helpers
  def next_column
    observation_matrix.observation_matrix_columns.where("position > ?", position).order(:position).first
  end

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

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

#observation_matrix_idInteger

Returns the observation matrix.

Returns:

  • (Integer)

    the observation matrix



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/observation_matrix_column.rb', line 23

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::Notes
  include Shared::IsData

  acts_as_list scope: [:observation_matrix_id, :project_id]

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  after_initialize :set_reference_count

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @return Scope
  #  There is no order to these Observations!  They do not follow the row order.
  def observations
    Observation.in_observation_matrix(observation_matrix_id).where(descriptor_id: descriptor_id)
  end

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  # TODO: belong in helpers
  def next_column
    observation_matrix.observation_matrix_columns.where("position > ?", position).order(:position).first
  end

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

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

#reference_countInteger

Returns a count of how many times this descriptor is referenced from observation_matrix_column_items. A column can be present via individual reference, or via reference through dynamic column sets.

Returns:

  • (Integer)

    a count of how many times this descriptor is referenced from observation_matrix_column_items. A column can be present via individual reference, or via reference through dynamic column sets.



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/observation_matrix_column.rb', line 23

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::Notes
  include Shared::IsData

  acts_as_list scope: [:observation_matrix_id, :project_id]

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  after_initialize :set_reference_count

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @return Scope
  #  There is no order to these Observations!  They do not follow the row order.
  def observations
    Observation.in_observation_matrix(observation_matrix_id).where(descriptor_id: descriptor_id)
  end

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  # TODO: belong in helpers
  def next_column
    observation_matrix.observation_matrix_columns.where("position > ?", position).order(:position).first
  end

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

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

Class Method Details

.sort(array) ⇒ Object

Returns true incrementally sort the supplied ids.

Parameters:

  • array (Array)

Returns:

  • true incrementally sort the supplied ids



48
49
50
51
52
53
# File 'app/models/observation_matrix_column.rb', line 48

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

Instance Method Details

#next_columnObject

TODO: belong in helpers



56
57
58
# File 'app/models/observation_matrix_column.rb', line 56

def next_column
  observation_matrix.observation_matrix_columns.where("position > ?", position).order(:position).first
end

#observationsObject

Returns Scope There is no order to these Observations! They do not follow the row order.

Returns:

  • Scope There is no order to these Observations! They do not follow the row order.



41
42
43
# File 'app/models/observation_matrix_column.rb', line 41

def observations
  Observation.in_observation_matrix(observation_matrix_id).where(descriptor_id: descriptor_id)
end

#previous_columnObject



60
61
62
# File 'app/models/observation_matrix_column.rb', line 60

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

#set_reference_countObject (protected)



66
67
68
# File 'app/models/observation_matrix_column.rb', line 66

def set_reference_count
  reference_count ||= 0
end