class SocialSecurityNumber::Lv

SocialSecurityNumber::Lv Latvian Personal Code (Personas kods) en.wikipedia.org/wiki/National_identification_number#Latvia ec.europa.eu/taxation_customs/tin/pdf/en/TIN_-_country_sheet_LV_en.pdf

Constants

CONTROLCIPHERS
MODULUS
REGEXP_NEW
REGEXP_OLD

Public Instance Methods

validate() click to toggle source
# File lib/social_security_number/country/lv.rb, line 6
def validate
  @error = 'bad number format' unless validate_formats
end

Private Instance Methods

base_year(year) click to toggle source
# File lib/social_security_number/country/lv.rb, line 39
def base_year(year)
  current_year = Time.now.year % 100
  offset_year = year.to_i
  offset_year += 100 if year && offset_year < current_year
  1900 + offset_year
end
check_control_sum() click to toggle source
# File lib/social_security_number/country/lv.rb, line 46
def check_control_sum
  puts count_last_number
  puts @civil_number[10].to_i
  count_last_number == @civil_number[10].to_i
end
check_date() click to toggle source
# File lib/social_security_number/country/lv.rb, line 31
def check_date
  day = @civil_number[0..1]
  month = @civil_number[2..3]
  year = @civil_number[4..6]

  Date.valid_date?(base_year(year).to_i, month.to_i, day.to_i)
end
check_new_format() click to toggle source
# File lib/social_security_number/country/lv.rb, line 23
def check_new_format
  check_by_regexp(REGEXP_NEW)
end
check_old_format() click to toggle source
# File lib/social_security_number/country/lv.rb, line 27
def check_old_format
  check_by_regexp(REGEXP_OLD) && check_date && check_control_sum
end
count_last_number() click to toggle source
# File lib/social_security_number/country/lv.rb, line 52
def count_last_number
  sum = 1 + calc_sum(@civil_number[0..9], CONTROLCIPHERS)
  sum % MODULUS % 10
end
validate_formats() click to toggle source
# File lib/social_security_number/country/lv.rb, line 19
def validate_formats
  check_new_format || check_old_format
end