Class: Valideez::Pesel
- Includes:
- Common
- Defined in:
- lib/valideez/pesel.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(val, options = {}) ⇒ Pesel
constructor
A new instance of Pesel.
- #validate_age ⇒ Object
- #validate_sum_control ⇒ Object
Methods included from Common
#validate_format, #validate_length
Methods inherited from Base
Constructor Details
#initialize(val, options = {}) ⇒ Pesel
Returns a new instance of Pesel.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/valideez/pesel.rb', line 7 def initialize(val, = {}) super val assign({ :length => 11, :format => /\A\d{11}\Z/, :mask => [1, 3, 7, 9, 1, 3, 7, 9, 1, 3], :modulo => 10, :age => 0, :sum_control => true, }.merge()) @arr = [] end |
Instance Method Details
#validate_age ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/valideez/pesel.rb', line 30 def validate_age now = Time.now y = (now.strftime("%Y").to_i - age).to_s m = now.strftime("%m") d = now.strftime("%d") age == 0 || convert_to_date(val[0..5]) <= Date.parse([y, m, d].join("-")) end |
#validate_sum_control ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/valideez/pesel.rb', line 22 def validate_sum_control mod = checksum % modulo mod = modulo - mod mod = 0 if mod == modulo mod === @arr.shift end |