Class: RangedLotCategory

Inherits:
ActiveRecord::Base
  • Object
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

Constant Summary

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from SoftValidation

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

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Attribute Details

- (Integer) maximum_value

TODO:

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
50
51
52
53
54
55
56
57
58
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ActiveRecord::Base
  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)

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  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

  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

- (Integer) minimum_value

TODO:

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
50
51
52
53
54
55
56
57
58
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ActiveRecord::Base
  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)

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  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

  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

- (String) name

TODO:

Returns:

  • (String)


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
50
51
52
53
54
55
56
57
58
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ActiveRecord::Base
  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)

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  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

  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

- (Integer) project_id

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
50
51
52
53
54
55
56
57
58
# File 'app/models/ranged_lot_category.rb', line 21

class RangedLotCategory < ActiveRecord::Base
  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)

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

  protected

  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

  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

Class Method Details

+ (Object) generate_download(scope)



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

def self.generate_download(scope)
  CSV.generate do |csv|
    csv << column_names
    scope.order(id: :asc).find_each do |o|
      csv << o.attributes.values_at(*column_names).collect { |i|
        i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
      }
    end
  end
end

Instance Method Details

- (Object) sv_range_does_not_overlap (protected)



54
55
56
# File 'app/models/ranged_lot_category.rb', line 54

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

- (Object) validate_values (protected)



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

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