class ActiveModel::Validations::AbnValidator
Constants
- ABN_WEIGHTS
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/active_model/validations/abn_validator.rb, line 9 def validate_each(record, attribute, value) return if value.nil? || value == '' abn = value.delete(' ').split('').map(&:to_i) if abn.length != 11 record.errors.add attribute, :invalid_abn_length, value: value return end abn[0] = abn[0] - 1 record.errors.add attribute, :invalid_abn, value: value unless abn.zip(ABN_WEIGHTS).map{|a,w|a*w}.inject(:+)/89.00 % 1 == 0 end