Class: MagickNumbers::Pesel

Inherits:
Base
  • Object
show all
Defined in:
lib/magick_numbers/pesel.rb

Instance Attribute Summary

Attributes inherited from Base

#length, #magick_array, #magick_number, #mask, #modulo, #regexp

Instance Method Summary collapse

Methods inherited from Base

#checksum, #valid?, #validate, #validate_length, #validate_regexp

Constructor Details

#initialize(num) ⇒ Pesel

Returns a new instance of Pesel.



5
6
7
8
9
10
11
# File 'lib/magick_numbers/pesel.rb', line 5

def initialize(num)
  super num
  @mask = [ 1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
  @modulo = 10
  @regexp = /\d{11}/
  @length = 11
end

Instance Method Details

#validate_sum_controlObject



13
14
15
16
17
18
# File 'lib/magick_numbers/pesel.rb', line 13

def validate_sum_control
  mod = checksum % modulo
  mod = 10 - mod
  mod = 0 if mod == 10
  mod === magick_array.shift
end