Class: RutValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validator.rb

Overview

Validates if the given string has the correct rut/run syntax and if the rut/run has the correct digit.

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Parameters:

  • value (String)

    the string to be validated



8
9
10
11
12
# File 'lib/validator.rb', line 8

def validate_each(record, attribute, value)
  unless value.rut_valid?
    record.errors[attribute] << (options[:message] || "is not a valid rut")
  end
end