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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77cae4842c7d2d690759f9399e75d65fea06359d
4
- data.tar.gz: 0bf287d98e0e2d516553fb49903cc6d3178d8117
3
+ metadata.gz: 0d078496a9e5e3d59cf848f8e688e77684a5df62
4
+ data.tar.gz: 400e756356573821582f4d66b4d78238bec532cf
5
5
  SHA512:
6
- metadata.gz: dd6cf178bc235f330ab2e6f80f2fc37a692aba66cf1ef46dfa144418f30dc3399164b8a94ee9ede2a7e64b44dbe8335ccd41b7ae57a4337cd622f135df87e942
7
- data.tar.gz: 8d87e7e1cb501d9b15591e69db5239a64e4e180f22f9f29fcc64c21769a77915c1dbeb6e44265c160c5fd3245e6b42947f0fad4fc6cf6c3108c1bd10647d3cb0
6
+ metadata.gz: 32824e28abc137a157b0bd7399726a58e96df0c213eecd2b893c28fb095059161036915ff1718d12a1590a1cc62d7adf8f62878a41bf05c190516fd1d5d104de
7
+ data.tar.gz: 140f05aa7c5dbf5aedac2643ef6ef591b77cfb88a218902c9c817ae102ba1b4115b5979e35c23a38c9836e35eb893d2e98f97ca8e7acd0776a91aa71e975d409
@@ -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 = case
26
- when (100..101).cover?(checksum)
27
- 0
28
- when checksum > 101
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 (0..9) }.join
62
+ digits = Array.new(9).map{ rand(10) }.join
67
63
  sum = self.new(digits).checksum
68
64
  "#{digits}#{sum}"
69
65
  end
@@ -1,3 +1,3 @@
1
1
  class Snils
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Novikov