Created
March 23, 2016 09:29
-
-
Save Sobak/e0fae5f3df3f062c6b6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PeselValidate | |
@@weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1] | |
def initialize(str1) | |
@pesel = str1 | |
end | |
def validate | |
numbers = @pesel.split(//).map(&:to_i) | |
sum = 0 | |
numbers.each_with_index do |number, position| | |
sum += number * @@weights[position] | |
end | |
sum % 10 == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment