Class: Parxer::Validator::Rut

Inherits:
Base
  • Object
show all
Defined in:
lib/parxer/validators/rut_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#id, #initialize

Constructor Details

This class inherits a constructor from Parxer::Validator::Base

Instance Method Details

#validateObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/parxer/validators/rut_validator.rb', line 4

def validate
  rut = clean_rut
  return true if rut.blank?
  t = rut[0...-1].to_i
  m = 0
  s = 1
  while t.positive?
    s = (s + t % 10 * (9 - m % 6)) % 11
    m += 1
    t /= 10
  end
  v = if s.positive? then (s - 1).to_s else 'K' end
  (v == rut.last.upcase)
rescue
  false
end