social_security_number 0.1.3 → 0.1.6

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: 378d7a24acce37a5892f40b48ee957780f883e02
4
- data.tar.gz: d921f7b1548049a44e2e9ef6ab1fa7d34b68f6b4
3
+ metadata.gz: 3ef6989bf26efcb10701d734422c3dd9c9bc5a21
4
+ data.tar.gz: 07fd10da85a51a18fd7bd29caebe2eda7b14fac0
5
5
  SHA512:
6
- metadata.gz: d76a21a8530caf46b2d6e87e6c10581d71b59987577779a421f4f75d8bcabb319537ad00effa5e8866d5e18f03b2da726b800851757a30272ece668f85606c93
7
- data.tar.gz: bcc2bbae831a6fa32c6ccc81ba7c50d9252bf40cf4ad9df4c5f7a309f948eaee954abd2961b925b0b8d8029c2227d35fb5e3be07e3f952ad647fe732e0457df4
6
+ metadata.gz: 71b5c235966d7fbafbe94605d9cb86df67a01f81081d56cb3ba175ab094265b0520b01bdeda3ade1e503d9f410dc8fdf26bec9a1b7bc2fc34537de6e0ae41c11
7
+ data.tar.gz: bb8a3814b5e69ef5246a47578ef5b78fc8dd000344da1f83b4646e32fdd2002f05d59658ebc15827e3ae7332dadf365bd350af4ed0d72c91bac4df52ff50dc3f
@@ -32,18 +32,22 @@ module SocialSecurityNumber
32
32
 
33
33
  CONTROLCIPHERS = [2, 1, 2, 1, 2, 1, 2, 1, 2].freeze
34
34
 
35
- REGEXP = /^#{DATE_REGEXP}-(?<indv>\d{2})(?<gnd>\d{1})(?<ctrl>\d{1})$/
35
+ YEAR_REGEXP = /(?<year>(\d{2}){0,1}(\d{2}))/
36
+ DATE_REGEXP = /#{YEAR_REGEXP}(?<month>\d{2})(?<day>\d{2})/
37
+ REGEXP = /^#{DATE_REGEXP}[- +]?(?<indv>\d{2})(?<gnd>\d{1})(?<ctrl>\d{0,1})$/
36
38
 
37
39
  def check_control_digit
38
40
  sum = checksum(:even)
39
41
  control_number = (sum % 10 != 0) ? 10 - (sum % 10) : 0
42
+ return true if @control_number.to_s.empty?
40
43
  control_number.to_i == @control_number.to_i
41
44
  end
42
45
 
43
46
  def checksum(operation)
44
47
  i = 0
45
48
  compare_method = operation == :even ? :== : :>
46
- digit_number[2..10].reverse.split('').reduce(0) do |sum, c|
49
+ numer = @civil_number.gsub(/\-|\+/, '').to_s.length == 10 ? digit_number[0..8] : digit_number[2..10]
50
+ numer.reverse.split('').reduce(0) do |sum, c|
47
51
  n = c.to_i
48
52
  weight = (i % 2).send(compare_method, 0) ? n * 2 : n
49
53
  i += 1
@@ -1,3 +1,3 @@
1
1
  module SocialSecurityNumber
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_security_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SameSystem
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-20 00:00:00.000000000 Z
11
+ date: 2017-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler