social_security_number 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 042c2456a881cd2cb0e3cea300bc9fa892397a3a
4
- data.tar.gz: 68975f6e3b98ef821c4b67551b72d0f6aec7e5dc
3
+ metadata.gz: e30eadd9ced9fb48993528bbe920ac5e741e709a
4
+ data.tar.gz: 3f14c88345fb09471f44787ba8cd76e6029f67f9
5
5
  SHA512:
6
- metadata.gz: b2ba939c8082929ed99bae51224ac0586fdaf935704f7fa02a4a3462fae694f1e845ebb270e29d59f39201db7cf31fbece6706689bb749f39a75201105f5433d
7
- data.tar.gz: 04ae85bdc5c073391f910b65bdd1dcecc9d336df9cbab480f02de5e71b7c487b3b177aeb9c7e2e8f2f38291ca9712d18d5756fc549b049a904cdf4f288167166
6
+ metadata.gz: 135f9785d9096a99a69d2065ff3aa07298b3e8ef3893cf0080b48ef87085b9ec4ba48c9c6f697edc8c8b16f7c4580781862daf8886e2b22bd6d2059f669ffeef
7
+ data.tar.gz: f3f5e81768cebb4167862f4333ebef1ddf3f92e49da77b21b3c243af1fb8d4f5b94efe4a7d69d1398a262071fde99c6b568c0c711c26b1242d02769784ac7266
data/README.md CHANGED
@@ -18,6 +18,7 @@ Find version information in the CHANGELOG.
18
18
  * Ireland Personal Public Service Number (PPS No)
19
19
  * Iceland personal and organisation identity code (Kennitala)
20
20
  * Italy tax code for individuals (Codice fiscale)
21
+ * Latvian Personal Code (Personas kods)
21
22
  * Lithuania Personal Code (Asmens kodas)
22
23
  * Mexico Unique Population Registry Code (Clave Única de Registro de Población (CURP))
23
24
  * Netherlands Citizen's Service Number (Burgerservicenummer)
@@ -0,0 +1,57 @@
1
+ module SocialSecurityNumber
2
+ # SocialSecurityNumber::Lv Latvian Personal Code (Personas kods)
3
+ # https://en.wikipedia.org/wiki/National_identification_number#Latvia
4
+ # https://ec.europa.eu/taxation_customs/tin/pdf/en/TIN_-_country_sheet_LV_en.pdf
5
+ class Lv < Country
6
+ def validate
7
+ @error = 'bad number format' unless validate_formats
8
+ end
9
+
10
+ private
11
+
12
+ MODULUS = 11
13
+
14
+ CONTROLCIPHERS = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9].freeze
15
+
16
+ REGEXP_NEW = /^32(?<indv>\d{8})(?<ctrl>\d{1})$/
17
+ REGEXP_OLD = /^#{SHORT_DATE_REGEXP}(?<gnd>\d{1})(?<indv>\d{3})(?<ctrl>\d{1})$/
18
+
19
+ def validate_formats
20
+ check_new_format || check_old_format
21
+ end
22
+
23
+ def check_new_format
24
+ check_by_regexp(REGEXP_NEW)
25
+ end
26
+
27
+ def check_old_format
28
+ check_by_regexp(REGEXP_OLD) && check_date && check_control_sum
29
+ end
30
+
31
+ def check_date
32
+ day = @civil_number[0..1]
33
+ month = @civil_number[2..3]
34
+ year = @civil_number[4..6]
35
+
36
+ Date.valid_date?(base_year(year).to_i, month.to_i, day.to_i)
37
+ end
38
+
39
+ def base_year(year)
40
+ current_year = Time.now.year % 100
41
+ offset_year = year.to_i
42
+ offset_year += 100 if year && offset_year < current_year
43
+ 1900 + offset_year
44
+ end
45
+
46
+ def check_control_sum
47
+ puts count_last_number
48
+ puts @civil_number[10].to_i
49
+ count_last_number == @civil_number[10].to_i
50
+ end
51
+
52
+ def count_last_number
53
+ sum = 1 + calc_sum(@civil_number[0..9], CONTROLCIPHERS)
54
+ sum % MODULUS % 10
55
+ end
56
+ end
57
+ end
@@ -2,7 +2,7 @@ module SocialSecurityNumber
2
2
  # SocialSecurityNumber::Validator
3
3
  class Validator
4
4
  SUPPORTED_COUNTRY_CODES = %w[BE CA CH CN CZ DE DK EE ES FI FR GB IE
5
- IS IT LT MX NL NO PK SE US].freeze
5
+ IS IT LT LV MX NL NO PK SE US].freeze
6
6
 
7
7
  attr_accessor :civil_number, :country_code, :error
8
8
 
@@ -35,6 +35,5 @@ module SocialSecurityNumber
35
35
  @error = civil_number.error
36
36
  false
37
37
  end
38
-
39
38
  end
40
39
  end
@@ -1,3 +1,3 @@
1
1
  module SocialSecurityNumber
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["devops@samesystem.com"]
11
11
 
12
12
  spec.summary = %q{It provides validators for national identification numbers.}
13
- spec.description = %q{It provides validators for national identification numbers. Currently the following countries are supported: Belgium, Canada, China, Czech Republic, Denmark, Estonia, Germany, Finland, France, Iceland, Ireland, Italy, Lithuania, Mexico, Netherlands, Norway, Pakistan, Spain, Sweden, Switzerland, United Kingdom, United States }
13
+ spec.description = %q{It provides validators for national identification numbers. Currently the following countries are supported: Belgium, Canada, China, Czech Republic, Denmark, Estonia, Germany, Finland, France, Iceland, Ireland, Italy, Latvia, Lithuania, Mexico, Netherlands, Norway, Pakistan, Spain, Sweden, Switzerland, United Kingdom, United States }
14
14
  spec.homepage = "https://github.com/samesystem/social_security_number"
15
15
  spec.license = "MIT"
16
16
 
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - SameSystem
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-28 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,8 +54,9 @@ dependencies:
54
54
  version: '3.0'
55
55
  description: 'It provides validators for national identification numbers. Currently
56
56
  the following countries are supported: Belgium, Canada, China, Czech Republic, Denmark,
57
- Estonia, Germany, Finland, France, Iceland, Ireland, Italy, Lithuania, Mexico, Netherlands,
58
- Norway, Pakistan, Spain, Sweden, Switzerland, United Kingdom, United States '
57
+ Estonia, Germany, Finland, France, Iceland, Ireland, Italy, Latvia, Lithuania, Mexico,
58
+ Netherlands, Norway, Pakistan, Spain, Sweden, Switzerland, United Kingdom, United
59
+ States '
59
60
  email:
60
61
  - devops@samesystem.com
61
62
  executables: []
@@ -90,6 +91,7 @@ files:
90
91
  - lib/social_security_number/country/is.rb
91
92
  - lib/social_security_number/country/it.rb
92
93
  - lib/social_security_number/country/lt.rb
94
+ - lib/social_security_number/country/lv.rb
93
95
  - lib/social_security_number/country/mx.rb
94
96
  - lib/social_security_number/country/nl.rb
95
97
  - lib/social_security_number/country/no.rb