e-id 0.1.0 → 0.2.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: d82dd14ab7c405cf592f69017866eaed44e4be02a5d0428e51d0a712619d50d2
4
+ data.tar.gz: b0f1f1b88b5f72883d7f7ed4cf43e9ad994d044a48af065e7841a1729a841afb
5
5
  SHA512:
6
- metadata.gz: 5ac32ed7526f059926411f54cfd64f950b554868c704246206157a77776c8a3201a6441921e1e6143b4e2804a5799abc90d2fd3bb49e8ae4de9a0b26acc6568c
7
- data.tar.gz: f27d33289cebfc93546ec3d52927cd305884f400886e2d158ad5128c6bb8b83c7e1571f6ffb1fcea2a9362d487652091898cd2b05c02e7c1e660fc14481becb4
6
+ metadata.gz: fde6576e67495270052e3b9510ec0b8b227ae3e6861b74bf20c6b6258253254f1aecf7bacfec483597a256abe3ad4eaca9bfabb041aade4b544271d7af6d638b
7
+ data.tar.gz: aaaf1daf66461d6d274730475b9cdaeae8c0e025e97467a13571a64ff064b637f427de43c797a2a46ae21c4e0711712b469f20bf274297d9b363aa649be4983d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change log
2
2
 
3
+ ## v0.2.0
4
+
5
+ * Support Finland and Lithuania identity codes
6
+
3
7
  ## v0.1.0
4
8
 
5
- * Initial release
9
+ * 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.2.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
+ - [ ] 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.2.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/lib/e-id.rb CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  require 'eid/core'
4
4
  require 'eid/estonia'
5
+ require 'eid/finland'
6
+ require 'eid/lithuania'
5
7
  require 'eid/version'
data/lib/eid/core.rb CHANGED
@@ -7,5 +7,13 @@ module Eid
7
7
  def initialize(identity)
8
8
  @identity = identity.to_s
9
9
  end
10
+
11
+ def gender
12
+ female? ? :female : :male
13
+ end
14
+
15
+ def age
16
+ Date.today.year - birth_date&.year.to_i
17
+ end
10
18
  end
11
19
  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
@@ -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.2.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.2.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-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,8 @@ files:
69
69
  - lib/e-id.rb
70
70
  - lib/eid/core.rb
71
71
  - lib/eid/estonia.rb
72
+ - lib/eid/finland.rb
73
+ - lib/eid/lithuania.rb
72
74
  - lib/eid/version.rb
73
75
  homepage: https://github.com/tab/e-id
74
76
  licenses:
@@ -78,7 +80,7 @@ metadata:
78
80
  source_code_uri: https://github.com/tab/e-id
79
81
  changelog_uri: https://github.com/tab/e-id/blob/master/CHANGELOG.md
80
82
  rubygems_mfa_required: 'true'
81
- post_install_message:
83
+ post_install_message:
82
84
  rdoc_options: []
83
85
  require_paths:
84
86
  - lib
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  version: '0'
95
97
  requirements: []
96
98
  rubygems_version: 3.3.26
97
- signing_key:
99
+ signing_key:
98
100
  specification_version: 4
99
101
  summary: Electronic identity in Estonia and in other countries
100
102
  test_files: []