module IdentityCode

Constants

NUM_DAYS
SUPPORTED_COUNTRY_CODES
VERSION

Public Class Methods

age_correction(birth_date) click to toggle source
# File lib/identity_code.rb, line 56
def self.age_correction(birth_date)
  now = Time.now.utc.to_date
  return 0 if now.month > birth_date.month
  return 0 if now.month == birth_date.month && now.day >= birth_date.day
  1
end
generate(opts = {}) click to toggle source
# File lib/identity_code.rb, line 24
def self.generate(opts = {})
  country_code = opts[:country]
  raise 'Country param is missing or invalid (ee | lv | pl)' unless begin
    country_code &&
    SUPPORTED_COUNTRY_CODES.include?(country_code.downcase.to_sym)
  end

  Object.const_get("IdentityCode::#{country_code.upcase}").generate(opts)
end
valid?(opts = {}) click to toggle source
# File lib/identity_code.rb, line 45
def self.valid?(opts = {})
  country_code = opts.delete(:country)
  raise 'Country param is missing or invalid (ee | lv | pl)' unless begin
    country_code &&
    SUPPORTED_COUNTRY_CODES.include?(country_code.downcase.to_sym)
  end

  code = opts.delete(:code)
  Object.const_get("IdentityCode::#{country_code.upcase}").valid?(code)
end
validate(opts = {}) click to toggle source
# File lib/identity_code.rb, line 34
def self.validate(opts = {})
  country_code = opts.delete(:country)
  raise 'Country param is missing or invalid (ee | lv | pl)' unless begin
    country_code &&
    SUPPORTED_COUNTRY_CODES.include?(country_code.downcase.to_sym)
  end

  code = opts.delete(:code)
  Object.const_get("IdentityCode::#{country_code.upcase}").new(code)
end