Class: RangedLotCategory

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::IsData, SoftValidation
Defined in:
app/models/ranged_lot_category.rb

Overview

A RangedLotCategory is an estimate used to assert that a CollectoinObject contains somewhere between a minimum and maximum number of individuals, as asserted by a curator of that CollectionObject. When a RangedLotCategory is assigned to a CollectionObject then no CollectionObject#total can be provided.

Constant Summary

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

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 Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#maximum_valueInteger

Returns the maximum number of enumerated objects.

Returns:

  • (Integer)

    the maximum number of enumerated objects



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
48
49
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include SoftValidation

  validates_presence_of :name, :minimum_value
  validate :validate_values
  validates :minimum_value, numericality: {greater_than: 0, only_integer: true}, allow_nil: false
  validates :maximum_value, numericality: {greater_than: 1, only_integer: true}, allow_nil: false

  validates_uniqueness_of :name, scope: [:project_id]

  has_many :ranged_lots, inverse_of: :ranged_lot_category, dependent: :restrict_with_error

  soft_validate(:sv_range_does_not_overlap)

  protected

  # @return [Object]
  def validate_values
    errors.add(:maximum_value, 'minimum value must be less than maximum value') if self.minimum_value && self.maximum_value && (self.minimum_value >= self.maximum_value)
  end

  # @return [Object]
  def sv_range_does_not_overlap
    soft_validations.add(:minimum_value, 'The range of values overlaps with another defined range of values.') if RangedLotCategory.where('minimum_value >= ? and maximum_value <= ? and project_id = ?', minimum_value, maximum_value, project_id)
  end

end

#minimum_valueInteger

Returns the minimum number of enumerated objects.

Returns:

  • (Integer)

    the minimum number of enumerated objects



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
48
49
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include SoftValidation

  validates_presence_of :name, :minimum_value
  validate :validate_values
  validates :minimum_value, numericality: {greater_than: 0, only_integer: true}, allow_nil: false
  validates :maximum_value, numericality: {greater_than: 1, only_integer: true}, allow_nil: false

  validates_uniqueness_of :name, scope: [:project_id]

  has_many :ranged_lots, inverse_of: :ranged_lot_category, dependent: :restrict_with_error

  soft_validate(:sv_range_does_not_overlap)

  protected

  # @return [Object]
  def validate_values
    errors.add(:maximum_value, 'minimum value must be less than maximum value') if self.minimum_value && self.maximum_value && (self.minimum_value >= self.maximum_value)
  end

  # @return [Object]
  def sv_range_does_not_overlap
    soft_validations.add(:minimum_value, 'The range of values overlaps with another defined range of values.') if RangedLotCategory.where('minimum_value >= ? and maximum_value <= ? and project_id = ?', minimum_value, maximum_value, project_id)
  end

end

#nameString

Returns a label for the category.

Returns:

  • (String)

    a label for the category



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
48
49
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include SoftValidation

  validates_presence_of :name, :minimum_value
  validate :validate_values
  validates :minimum_value, numericality: {greater_than: 0, only_integer: true}, allow_nil: false
  validates :maximum_value, numericality: {greater_than: 1, only_integer: true}, allow_nil: false

  validates_uniqueness_of :name, scope: [:project_id]

  has_many :ranged_lots, inverse_of: :ranged_lot_category, dependent: :restrict_with_error

  soft_validate(:sv_range_does_not_overlap)

  protected

  # @return [Object]
  def validate_values
    errors.add(:maximum_value, 'minimum value must be less than maximum value') if self.minimum_value && self.maximum_value && (self.minimum_value >= self.maximum_value)
  end

  # @return [Object]
  def sv_range_does_not_overlap
    soft_validations.add(:minimum_value, 'The range of values overlaps with another defined range of values.') if RangedLotCategory.where('minimum_value >= ? and maximum_value <= ? and project_id = ?', minimum_value, maximum_value, project_id)
  end

end

#project_idInteger

the project ID

Returns:

  • (Integer)


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
48
49
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include SoftValidation

  validates_presence_of :name, :minimum_value
  validate :validate_values
  validates :minimum_value, numericality: {greater_than: 0, only_integer: true}, allow_nil: false
  validates :maximum_value, numericality: {greater_than: 1, only_integer: true}, allow_nil: false

  validates_uniqueness_of :name, scope: [:project_id]

  has_many :ranged_lots, inverse_of: :ranged_lot_category, dependent: :restrict_with_error

  soft_validate(:sv_range_does_not_overlap)

  protected

  # @return [Object]
  def validate_values
    errors.add(:maximum_value, 'minimum value must be less than maximum value') if self.minimum_value && self.maximum_value && (self.minimum_value >= self.maximum_value)
  end

  # @return [Object]
  def sv_range_does_not_overlap
    soft_validations.add(:minimum_value, 'The range of values overlaps with another defined range of values.') if RangedLotCategory.where('minimum_value >= ? and maximum_value <= ? and project_id = ?', minimum_value, maximum_value, project_id)
  end

end

Instance Method Details

#sv_range_does_not_overlapObject (protected)

Returns:

  • (Object)


45
46
47
# File 'app/models/ranged_lot_category.rb', line 45

def sv_range_does_not_overlap
  soft_validations.add(:minimum_value, 'The range of values overlaps with another defined range of values.') if RangedLotCategory.where('minimum_value >= ? and maximum_value <= ? and project_id = ?', minimum_value, maximum_value, project_id)
end

#validate_valuesObject (protected)

Returns:

  • (Object)


40
41
42
# File 'app/models/ranged_lot_category.rb', line 40

def validate_values
  errors.add(:maximum_value, 'minimum value must be less than maximum value') if self.minimum_value && self.maximum_value && (self.minimum_value >= self.maximum_value)
end