class SocialSecurityNumber::Mx

SocialSecurityNumber::Mx validates Mexico Unique Population Registry Code (Clave Única de Registro de Población (CURP)) es.stackoverflow.com/questions/31039/c%C3%B3mo-validar-una-curp-de-m%C3%A9xico en.wikipedia.org/wiki/Unique_Population_Registry_Code es.wikipedia.org/wiki/Registro_Federal_de_Contribuyentes_(M%C3%A9xico)

Constants

FEDERAL
FIC

the first internal consonants of surnames and names

LINIT

the first character is the initial of the first last name

LINIT_2

the initials of the second last name and the name

MODULUS
REGEXP
SURNAME

Public Instance Methods

gender() click to toggle source
# File lib/social_security_number/country/mx.rb, line 17
def gender
  @gender ||= @parsed_civil_number[:gnd].to_s == 'H' ? :male : :female
end
validate() click to toggle source
# File lib/social_security_number/country/mx.rb, line 7
def validate
  @error = if !check_by_regexp(REGEXP)
             'bad number format'
           elsif !birth_date
             'number birth date is invalid'
           elsif !check_control_sum
             'number control sum invalid'
           end
end

Private Instance Methods

check_control_sum() click to toggle source
# File lib/social_security_number/country/mx.rb, line 36
def check_control_sum
  count_last_number.to_i == @control_number.to_i
end
count_last_number() click to toggle source
# File lib/social_security_number/country/mx.rb, line 40
def count_last_number
  n = number
  alfabet = %W[0 1 2 3 4 5 6 7 8 9 A B C
    D E F G H I J K L M N Ñ O P Q R S T U V W X Y Z]
  sum = 0
  17.times do |i|
    sum += alfabet.index(n[i]).to_i * (18 - i)
  end
  last_number = 10 - sum % MODULUS
  last_number == 10 ? 0 : last_number
end
number() click to toggle source
# File lib/social_security_number/country/mx.rb, line 52
def number
  @civil_number.gsub(' |.|-', '')
end