Class: ValidatesIdentity::ClRut::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/validates_identity/cl_rut/validator.rb

Constant Summary collapse

VALIDATION_REGULAR_EXPRESSION =
/^(\d{2})\.?(\d{3})\.?(\d{3})-?(\d{1}|K)$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Validator

Returns a new instance of Validator.



10
11
12
# File 'lib/validates_identity/cl_rut/validator.rb', line 10

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/validates_identity/cl_rut/validator.rb', line 8

def value
  @value
end

Instance Method Details

#formattedObject



21
22
23
24
25
# File 'lib/validates_identity/cl_rut/validator.rb', line 21

def formatted
  return if result.nil?

  "#{result[1]}.#{result[2]}.#{result[3]}-#{result[4]}"
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/validates_identity/cl_rut/validator.rb', line 14

def valid?
  return true if value.blank?
  return false if number.nil?

  verifier_digit == calculated_verifier_digit
end