Sha256: 843817f7bc6356235014df8f12be79b1e6aef72c4295d04427e0e8573f338827

Contents?: true

Size: 552 Bytes

Versions: 35

Compression:

Stored size: 552 Bytes

Contents

require_dependency "renalware"

module Renalware
  module NumericScaleValidations
    extend ActiveSupport::Concern
    def validate_numeric_scale(record, attribute, value, scale)
      if number_exceeds_scale?(value, scale)
        record.errors.add(attribute, :invalid_number)
      end
    end

    # Returns true for any integer or number to _scale_ decimal places
    # e.g. if scale is 1 then 11 or 11.1 return true but 11.11 returns false
    def number_exceeds_scale?(value, scale)
      value.to_f.round(scale) != value.to_f
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.15 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.14 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.13 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.12 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.11 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.9 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.8 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.7 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.5 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.4 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.3 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.2 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.1 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.0 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.0.pre.rc13 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.0.pre.rc11 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.0.pre.rc10 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.0.pre.rc9 app/validators/concerns/renalware/numeric_scale_validations.rb
renalware-core-2.0.0.pre.rc8 app/validators/concerns/renalware/numeric_scale_validations.rb