e-id 0.2.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: d82dd14ab7c405cf592f69017866eaed44e4be02a5d0428e51d0a712619d50d2
4
- data.tar.gz: b0f1f1b88b5f72883d7f7ed4cf43e9ad994d044a48af065e7841a1729a841afb
3
+ metadata.gz: 7f6d6da8667f2637e77c105d3a311bc4742a84250fc67c3d8add1ee20e4f45a6
4
+ data.tar.gz: e380f4ca4b67c6402d45e600f70b9daaea1cf9f13092683b8fd7ed42a9672a2c
5
5
  SHA512:
6
- metadata.gz: fde6576e67495270052e3b9510ec0b8b227ae3e6861b74bf20c6b6258253254f1aecf7bacfec483597a256abe3ad4eaca9bfabb041aade4b544271d7af6d638b
7
- data.tar.gz: aaaf1daf66461d6d274730475b9cdaeae8c0e025e97467a13571a64ff064b637f427de43c797a2a46ae21c4e0711712b469f20bf274297d9b363aa649be4983d
6
+ metadata.gz: 8976fee6f2850417ff7c987283202d3de7e03ca67867be2ced0f92d58702b4f7bbb3f1d3e079453b32285e7d6bfd2274ec11f431df151c47e334c18a4cdbc78a
7
+ data.tar.gz: 5b62029106040fbbe886a2ffe259091e3f5f6cfe2dd09310ab59db4d8cee40669d64ce03cf422dc8756fdbaff54bac70550b198e384ff65dc3a3612a62824649
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change log
2
2
 
3
+ ## v0.3.0
4
+
5
+ * Support Latvia identity codes
6
+
3
7
  ## v0.2.0
4
8
 
5
9
  * Support Finland and Lithuania identity codes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- e-id (0.2.0)
4
+ e-id (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -8,7 +8,7 @@ Electronic identity in Estonia and in other countries
8
8
  - [x] Finland
9
9
  - [ ] Sweden
10
10
  - [x] Lithuania
11
- - [ ] Latvia
11
+ - [x] Latvia
12
12
  - [ ] Denmark
13
13
 
14
14
  ## Installation
@@ -16,7 +16,7 @@ Electronic identity in Estonia and in other countries
16
16
  Add this line to your application's Gemfile:
17
17
 
18
18
  ```ruby
19
- gem 'e-id', '~> 0.2.0'
19
+ gem 'e-id', '~> 0.3.0'
20
20
  ```
21
21
 
22
22
  And then execute:
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
@@ -3,5 +3,6 @@
3
3
  require 'eid/core'
4
4
  require 'eid/estonia'
5
5
  require 'eid/finland'
6
+ require 'eid/latvia'
6
7
  require 'eid/lithuania'
7
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
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
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.2.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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-04 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
@@ -70,6 +71,7 @@ files:
70
71
  - lib/eid/core.rb
71
72
  - lib/eid/estonia.rb
72
73
  - lib/eid/finland.rb
74
+ - lib/eid/latvia.rb
73
75
  - lib/eid/lithuania.rb
74
76
  - lib/eid/version.rb
75
77
  homepage: https://github.com/tab/e-id