snils 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/snils.rb +5 -9
- data/lib/snils/version.rb +1 -1
- data/spec/snils_spec.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d078496a9e5e3d59cf848f8e688e77684a5df62
|
4
|
+
data.tar.gz: 400e756356573821582f4d66b4d78238bec532cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32824e28abc137a157b0bd7399726a58e96df0c213eecd2b893c28fb095059161036915ff1718d12a1590a1cc62d7adf8f62878a41bf05c190516fd1d5d104de
|
7
|
+
data.tar.gz: 140f05aa7c5dbf5aedac2643ef6ef591b77cfb88a218902c9c817ae102ba1b4115b5979e35c23a38c9836e35eb893d2e98f97ca8e7acd0776a91aa71e975d409
|
data/lib/snils.rb
CHANGED
@@ -22,14 +22,10 @@ class Snils
|
|
22
22
|
checksum = digits.each.with_index.inject(0) do |sum, (digit, index)|
|
23
23
|
sum + digit * (9 - index)
|
24
24
|
end
|
25
|
-
checksum
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
checksum % 101
|
30
|
-
else
|
31
|
-
checksum
|
32
|
-
end
|
25
|
+
while checksum > 101 do
|
26
|
+
checksum = checksum % 101
|
27
|
+
end
|
28
|
+
checksum = 0 if (100..101).include?(checksum)
|
33
29
|
'%02d' % checksum
|
34
30
|
end
|
35
31
|
|
@@ -63,7 +59,7 @@ class Snils
|
|
63
59
|
|
64
60
|
# Generates new random valid SNILS
|
65
61
|
def self.generate
|
66
|
-
digits = Array.new(9).map{ rand
|
62
|
+
digits = Array.new(9).map{ rand(10) }.join
|
67
63
|
sum = self.new(digits).checksum
|
68
64
|
"#{digits}#{sum}"
|
69
65
|
end
|
data/lib/snils/version.rb
CHANGED
data/spec/snils_spec.rb
CHANGED
@@ -97,6 +97,8 @@ describe Snils do
|
|
97
97
|
it 'calculates valid checksum even for incomplete snils' do
|
98
98
|
snils = described_class.new('188299822')
|
99
99
|
expect(snils.checksum).to eq('50')
|
100
|
+
snils = described_class.new('563-725-063')
|
101
|
+
expect(snils.checksum).to eq('00')
|
100
102
|
end
|
101
103
|
|
102
104
|
end
|