Module: Renalware::NumericScaleValidations
- Extended by:
- ActiveSupport::Concern
- Included in:
- Patients::BmStixValidator, Patients::HeightValidator, Patients::TemperatureValidator, Patients::WeightValidator
- Defined in:
- app/validators/concerns/renalware/numeric_scale_validations.rb
Instance Method Summary collapse
-
#number_exceeds_scale?(value, scale) ⇒ Boolean
Returns true for any integer or number to scale decimal places e.g.
- #validate_numeric_scale(record, attribute, value, scale) ⇒ Object
Instance Method Details
#number_exceeds_scale?(value, scale) ⇒ Boolean
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
16 17 18 |
# File 'app/validators/concerns/renalware/numeric_scale_validations.rb', line 16 def number_exceeds_scale?(value, scale) value.to_f.round(scale) != value.to_f end |
#validate_numeric_scale(record, attribute, value, scale) ⇒ Object
8 9 10 11 12 |
# File 'app/validators/concerns/renalware/numeric_scale_validations.rb', line 8 def validate_numeric_scale(record, attribute, value, scale) if number_exceeds_scale?(value, scale) record.errors.add(attribute, :invalid_number) end end |