class SocialSecurityNumber::Ca
SocialSecurityNumber::Ca
validates Canadian Social Insurance Numbers (SINs) The Social Insurance Number (SIN) is a 9-digit identifier issued to individuals for various government programs. SINs that begin with a 9 are issued to temporary workers who are neither Canadian citizens nor permanent residents. en.wikipedia.org/wiki/Social_Insurance_Number
Constants
- CONTROLCIPHERS
- MODULUS
- REGEXP
Public Instance Methods
validate()
click to toggle source
# File lib/social_security_number/country/ca.rb, line 9 def validate @error = if !check_by_regexp(REGEXP) 'bad number format' elsif !check_number 'number control sum invalid' end end
Private Instance Methods
check_number()
click to toggle source
# File lib/social_security_number/country/ca.rb, line 25 def check_number (count_number_sum % 10).zero? end
count_number_sum()
click to toggle source
# File lib/social_security_number/country/ca.rb, line 29 def count_number_sum digits = digit_number.split(//) new_number = [] sum = 0 digits.each_with_index do |digit, i| n = digit.to_i * CONTROLCIPHERS[i].to_i new_number << if n > 9 n - 9 else n end end new_number.each do |digit| sum += digit.to_i end sum end