e-id 0.1.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 95f1117835526ba0fa98a96f073c540d7cca1bd83016581060ec067f0280b746
4
- data.tar.gz: a866ae7a9bcba3feb047929dd983437f08dd3f052367c0b78b88b977884c4666
3
+ metadata.gz: 7f6d6da8667f2637e77c105d3a311bc4742a84250fc67c3d8add1ee20e4f45a6
4
+ data.tar.gz: e380f4ca4b67c6402d45e600f70b9daaea1cf9f13092683b8fd7ed42a9672a2c
5
5
  SHA512:
6
- metadata.gz: 5ac32ed7526f059926411f54cfd64f950b554868c704246206157a77776c8a3201a6441921e1e6143b4e2804a5799abc90d2fd3bb49e8ae4de9a0b26acc6568c
7
- data.tar.gz: f27d33289cebfc93546ec3d52927cd305884f400886e2d158ad5128c6bb8b83c7e1571f6ffb1fcea2a9362d487652091898cd2b05c02e7c1e660fc14481becb4
6
+ metadata.gz: 8976fee6f2850417ff7c987283202d3de7e03ca67867be2ced0f92d58702b4f7bbb3f1d3e079453b32285e7d6bfd2274ec11f431df151c47e334c18a4cdbc78a
7
+ data.tar.gz: 5b62029106040fbbe886a2ffe259091e3f5f6cfe2dd09310ab59db4d8cee40669d64ce03cf422dc8756fdbaff54bac70550b198e384ff65dc3a3612a62824649
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## v0.3.0
4
+
5
+ * Support Latvia identity codes
6
+
7
+ ## v0.2.0
8
+
9
+ * Support Finland and Lithuania identity codes
10
+
3
11
  ## v0.1.0
4
12
 
5
- * Initial release
13
+ * Initial release: support Estonia identity codes
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gemspec
9
9
  group :development, :test do
10
10
  gem 'rspec', '~> 3.12.0'
11
11
  gem 'rubocop', '~> 1.50.2'
12
- gem 'rubocop-performance', '~> 1.16.0'
12
+ gem 'rubocop-performance', '~> 1.17.1'
13
13
  gem 'rubocop-rspec', '~> 2.19.0'
14
14
  end
15
15
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- e-id (0.1.0)
4
+ e-id (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -44,7 +44,7 @@ GEM
44
44
  parser (>= 3.2.1.0)
45
45
  rubocop-capybara (2.18.0)
46
46
  rubocop (~> 1.41)
47
- rubocop-performance (1.16.0)
47
+ rubocop-performance (1.17.1)
48
48
  rubocop (>= 1.7.0, < 2.0)
49
49
  rubocop-ast (>= 0.4.0)
50
50
  rubocop-rspec (2.19.0)
@@ -69,7 +69,7 @@ DEPENDENCIES
69
69
  rake (~> 13.0.6)
70
70
  rspec (~> 3.12.0)
71
71
  rubocop (~> 1.50.2)
72
- rubocop-performance (~> 1.16.0)
72
+ rubocop-performance (~> 1.17.1)
73
73
  rubocop-rspec (~> 2.19.0)
74
74
  simplecov (~> 0.22.0)
75
75
 
data/README.md CHANGED
@@ -2,21 +2,34 @@
2
2
 
3
3
  Electronic identity in Estonia and in other countries
4
4
 
5
+ ## Supported countries
6
+
7
+ - [x] Estonia
8
+ - [x] Finland
9
+ - [ ] Sweden
10
+ - [x] Lithuania
11
+ - [x] Latvia
12
+ - [ ] Denmark
13
+
5
14
  ## Installation
6
15
 
7
16
  Add this line to your application's Gemfile:
8
17
 
9
18
  ```ruby
10
- gem 'e-id', '~> 0.1.0'
19
+ gem 'e-id', '~> 0.3.0'
11
20
  ```
12
21
 
13
22
  And then execute:
14
23
 
15
- $ bundle
24
+ ```bash
25
+ bundle
26
+ ```
16
27
 
17
28
  Or install it yourself as:
18
29
 
19
- $ gem install e-id
30
+ ```bash
31
+ gem install e-id
32
+ ```
20
33
 
21
34
  ## Usage
22
35
 
data/TODO.md ADDED
@@ -0,0 +1,8 @@
1
+ # Todo
2
+
3
+ - [x] Estonia national identity
4
+ - [x] Finland national identity
5
+ - [x] Lithuania national identity
6
+ - [x] Latvia national identity
7
+ - [ ] easy use in rails model (like validate_identity and mixins)
8
+ - [ ] ruby 2.4 support
data/lib/e-id.rb CHANGED
@@ -2,4 +2,7 @@
2
2
 
3
3
  require 'eid/core'
4
4
  require 'eid/estonia'
5
+ require 'eid/finland'
6
+ require 'eid/latvia'
7
+ require 'eid/lithuania'
5
8
  require 'eid/version'
data/lib/eid/core.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
4
+
3
5
  module Eid
4
6
  class Core
5
7
  attr_accessor :identity
@@ -7,5 +9,13 @@ module Eid
7
9
  def initialize(identity)
8
10
  @identity = identity.to_s
9
11
  end
12
+
13
+ def gender
14
+ female? ? :female : :male
15
+ end
16
+
17
+ def age
18
+ Date.today.year - birth_date&.year.to_i
19
+ end
10
20
  end
11
21
  end
data/lib/eid/estonia.rb CHANGED
@@ -3,13 +3,13 @@
3
3
  module Eid
4
4
  class Estonia < Core
5
5
  # NOTE: identity GYYMMDDSSSC
6
- # G – gender
6
+ # G – gender (even for female, odd for male)
7
7
  # YYMMDD – date of birth
8
8
  # SSS – serial number
9
9
  # C – checksum
10
10
 
11
11
  def valid?
12
- identity.size == 11 && birth_date.is_a?(Date)
12
+ valid_format? && birth_date.is_a?(Date)
13
13
  end
14
14
 
15
15
  def female?
@@ -20,22 +20,18 @@ module Eid
20
20
  identity[0].to_i.odd?
21
21
  end
22
22
 
23
- def gender
24
- female? ? :female : :male
25
- end
26
-
27
23
  def birth_date
28
24
  Date.new((century + identity[1..2].to_i), identity[3..4].to_i, identity[5..6].to_i)
29
25
  rescue StandardError
30
26
  nil
31
27
  end
32
28
 
33
- def age
34
- Date.today.year - birth_date&.year.to_i
35
- end
36
-
37
29
  private
38
30
 
31
+ def valid_format?
32
+ identity.match?(/\d{11}/) && identity.size == 11
33
+ end
34
+
39
35
  def century
40
36
  case identity[0].to_i
41
37
  when 1..2 then 1800
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eid
4
+ class Finland < Core
5
+ # NOTE: identity DDMMYYCZZZQ
6
+ # DDMMYY - date of birth
7
+ # C - century sign (+, -, U, V, W, X, Y, A, B, C, D, E, F)
8
+ # ZZZ - individual number (002-899 for permanent residents and Finnish citizens, 900-999 for temporary IDs)
9
+ # Q - control character (checksum)
10
+
11
+ VALID_CENTURY_SIGNS = %w[+ - U V W X Y A B C D E F].freeze
12
+ VALID_CONTROL_CHARACTERS = '0123456789ABCDEFHJKLMNPRSTUVWXY'
13
+
14
+ def valid?
15
+ return false unless identity.size == 11
16
+
17
+ birth_date.is_a?(Date) &&
18
+ VALID_CENTURY_SIGNS.include?(identity[6]) &&
19
+ VALID_CONTROL_CHARACTERS.include?(identity[10])
20
+ end
21
+
22
+ def female?
23
+ identity[7..9].to_i.even?
24
+ end
25
+
26
+ def male?
27
+ identity[7..9].to_i.odd?
28
+ end
29
+
30
+ def birth_date
31
+ Date.new(century + identity[4..5].to_i, identity[2..3].to_i, identity[0..1].to_i)
32
+ rescue StandardError
33
+ nil
34
+ end
35
+
36
+ private
37
+
38
+ def valid_format?
39
+ identity.size == 11
40
+ end
41
+
42
+ def century
43
+ case identity[6]
44
+ when '+' then 1800
45
+ when '-', 'U', 'V', 'W', 'X', 'Y' then 1900
46
+ when 'A', 'B', 'C', 'D', 'E', 'F' then 2000
47
+ else 2100
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/eid/latvia.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eid
4
+ class Latvia < Core
5
+ # NOTE: identity DDMMYY-XNNNZ
6
+ # DDMYY - date of birth
7
+ # X - century
8
+ # NNN - birth serial number
9
+ # Z - checksum digit
10
+ #
11
+ # 32XXXX-XXXXC (updated format since 01.07.2017)
12
+ # 32 - updated format indicator
13
+ # XXXX-XXXX - random numbers
14
+ # C - checksum
15
+
16
+ def legacy?
17
+ !identity.start_with?('32')
18
+ end
19
+
20
+ def valid?
21
+ legacy? ? (valid_format? && birth_date.is_a?(Date)) : valid_format?
22
+ end
23
+
24
+ def female?
25
+ raise 'Not supported'
26
+ end
27
+
28
+ def male?
29
+ raise 'Not supported'
30
+ end
31
+
32
+ def gender
33
+ raise 'Not supported'
34
+ end
35
+
36
+ def birth_date
37
+ Date.new(century + identity[4..5].to_i, identity[2..3].to_i, identity[0..1].to_i) if legacy?
38
+ rescue StandardError
39
+ nil
40
+ end
41
+
42
+ private
43
+
44
+ def valid_format?
45
+ identity.match?(/\d{6}-\d{5}/) && identity.size == 12
46
+ end
47
+
48
+ def century
49
+ case identity[7].to_i
50
+ when 1 then 1900
51
+ when 2 then 2000
52
+ else 2100
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eid
4
+ class Lithuania < Core
5
+ # NOTE: identity GYYMMDDNNNC
6
+ # G – gender (even for female, odd for male)
7
+ # YYMMDD – date of birth
8
+ # NNN – serial number
9
+ # C – checksum
10
+
11
+ def valid?
12
+ valid_format? && birth_date.is_a?(Date)
13
+ end
14
+
15
+ def female?
16
+ identity[0].to_i.even?
17
+ end
18
+
19
+ def male?
20
+ identity[0].to_i.odd?
21
+ end
22
+
23
+ def birth_date
24
+ Date.new((century + identity[1..2].to_i), identity[3..4].to_i, identity[5..6].to_i)
25
+ rescue StandardError
26
+ nil
27
+ end
28
+
29
+ private
30
+
31
+ def valid_format?
32
+ identity.match?(/\d{11}/) && identity.size == 11
33
+ end
34
+
35
+ def century
36
+ case identity[0].to_i
37
+ when 1..2 then 1800
38
+ when 3..4 then 1900
39
+ when 5..6 then 2000
40
+ else 2100
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/eid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eid
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tab
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-30 00:00:00.000000000 Z
11
+ date: 2023-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,6 +62,7 @@ files:
62
62
  - LICENSE.txt
63
63
  - README.md
64
64
  - Rakefile
65
+ - TODO.md
65
66
  - bin/console
66
67
  - bin/setup
67
68
  - docker-compose.yaml
@@ -69,6 +70,9 @@ files:
69
70
  - lib/e-id.rb
70
71
  - lib/eid/core.rb
71
72
  - lib/eid/estonia.rb
73
+ - lib/eid/finland.rb
74
+ - lib/eid/latvia.rb
75
+ - lib/eid/lithuania.rb
72
76
  - lib/eid/version.rb
73
77
  homepage: https://github.com/tab/e-id
74
78
  licenses:
@@ -78,7 +82,7 @@ metadata:
78
82
  source_code_uri: https://github.com/tab/e-id
79
83
  changelog_uri: https://github.com/tab/e-id/blob/master/CHANGELOG.md
80
84
  rubygems_mfa_required: 'true'
81
- post_install_message:
85
+ post_install_message:
82
86
  rdoc_options: []
83
87
  require_paths:
84
88
  - lib
@@ -94,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
98
  version: '0'
95
99
  requirements: []
96
100
  rubygems_version: 3.3.26
97
- signing_key:
101
+ signing_key:
98
102
  specification_version: 4
99
103
  summary: Electronic identity in Estonia and in other countries
100
104
  test_files: []