za_id_number 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.tool-versions +1 -0
- data/CHANGES +19 -0
- data/README.md +5 -5
- data/lib/za_id_number/version.rb +1 -1
- data/lib/za_id_number.rb +26 -11
- data/za_id_number.gemspec +2 -2
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1091207c4bf7fe86f9dd8eff09d907439d0c77d13596ce394145b958c487ca65
|
4
|
+
data.tar.gz: '08fbe6e7a50f19a8a3d395b66f2e49e1883728387d47c52cf8ff8da4fdaba4fc'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 650958c1b3305ad083b7b9ff0da547be34c292777c93635799e7bbdc04751fd74cd719761707832e4ea6d0d1d133dd5f2b887da9d21c5f201e8d6afc6b232d4c
|
7
|
+
data.tar.gz: d226d05b02865243ae604849da00669224b75984cd623947e54c97482fe0318157a490d0b65754e92dd49abdfbc69dee28239bfe01e0134526e262f903dfe672
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.6
|
data/CHANGES
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project tries really hard to adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
Nothing
|
11
|
+
|
12
|
+
## [2.1.0] - 2022-05-31
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
- `to_s` for easier string interpolation
|
17
|
+
- Add equality operator `==` and `eql?` method
|
18
|
+
- Add `hash` method
|
19
|
+
- Make id number instances immutable
|
data/README.md
CHANGED
@@ -52,11 +52,11 @@ id_number = ZAIDNumber.new('7501151234085') # => #<ZAIDNumber:0x00d40 @id_number
|
|
52
52
|
### Validation checks
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
id_num.
|
56
|
-
id_num.
|
57
|
-
id_num.
|
58
|
-
id_num.
|
59
|
-
id_num.
|
55
|
+
id_num.valid_length? # => true
|
56
|
+
id_num.only_digits? # => true
|
57
|
+
id_num.valid_date? # => true
|
58
|
+
id_num.valid_citizenship? # => true
|
59
|
+
id_num.valid_checksum? # => true
|
60
60
|
```
|
61
61
|
|
62
62
|
Or, roll up all those validation checks into one call:
|
data/lib/za_id_number/version.rb
CHANGED
data/lib/za_id_number.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'za_id_number/version'
|
2
4
|
require 'luhn'
|
5
|
+
require 'date'
|
3
6
|
|
4
7
|
class ZAIDNumber
|
5
8
|
REQUIRED_ID_LENGTH = 13
|
@@ -10,36 +13,37 @@ class ZAIDNumber
|
|
10
13
|
PERMANENT_RESIDENT = 1
|
11
14
|
|
12
15
|
attr_reader :id_number
|
16
|
+
alias to_s id_number
|
13
17
|
|
14
18
|
def initialize(id_num)
|
15
|
-
@id_number = id_num.to_s
|
19
|
+
@id_number = id_num.to_s.freeze
|
16
20
|
end
|
17
21
|
|
18
22
|
def valid?
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
valid_length? &&
|
24
|
+
only_digits? &&
|
25
|
+
valid_date? &&
|
26
|
+
valid_citizenship? &&
|
27
|
+
valid_checksum?
|
24
28
|
end
|
25
29
|
|
26
|
-
def
|
30
|
+
def valid_checksum?
|
27
31
|
Luhn.valid? @id_number
|
28
32
|
end
|
29
33
|
|
30
|
-
def
|
34
|
+
def valid_length?
|
31
35
|
@id_number.length == REQUIRED_ID_LENGTH
|
32
36
|
end
|
33
37
|
|
34
|
-
def
|
38
|
+
def only_digits?
|
35
39
|
@id_number.to_s.gsub(/\D*/, '') == @id_number.to_s
|
36
40
|
end
|
37
41
|
|
38
|
-
def
|
42
|
+
def valid_date?
|
39
43
|
date_of_birth ? true : false
|
40
44
|
end
|
41
45
|
|
42
|
-
def
|
46
|
+
def valid_citizenship?
|
43
47
|
CITIZENSHIP_RANGE.include? @id_number[10].to_i
|
44
48
|
end
|
45
49
|
|
@@ -72,4 +76,15 @@ class ZAIDNumber
|
|
72
76
|
def permanent_resident?
|
73
77
|
!za_citizen?
|
74
78
|
end
|
79
|
+
|
80
|
+
def ==(other)
|
81
|
+
return false unless other.is_a?(ZAIDNumber)
|
82
|
+
|
83
|
+
return id_number == other.id_number
|
84
|
+
end
|
85
|
+
alias eql? ==
|
86
|
+
|
87
|
+
def hash
|
88
|
+
id_number.hash
|
89
|
+
end
|
75
90
|
end
|
data/za_id_number.gemspec
CHANGED
@@ -32,9 +32,9 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
34
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
35
|
-
spec.add_development_dependency 'rake', '~>
|
35
|
+
spec.add_development_dependency 'rake', '~> 13.0.3'
|
36
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
-
spec.add_development_dependency 'pry', '~> 0.
|
37
|
+
spec.add_development_dependency 'pry', '~> 0.14.0'
|
38
38
|
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
39
39
|
|
40
40
|
spec.add_dependency 'luhn', '~> 1.0', '>= 1.0.2'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: za_id_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Fortuna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 13.0.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 13.0.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.14.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.14.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: awesome_print
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +110,9 @@ extra_rdoc_files: []
|
|
110
110
|
files:
|
111
111
|
- ".gitignore"
|
112
112
|
- ".rspec"
|
113
|
+
- ".tool-versions"
|
113
114
|
- ".travis.yml"
|
115
|
+
- CHANGES
|
114
116
|
- CODE_OF_CONDUCT.md
|
115
117
|
- Gemfile
|
116
118
|
- LICENSE.txt
|
@@ -141,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
143
|
- !ruby/object:Gem::Version
|
142
144
|
version: '0'
|
143
145
|
requirements: []
|
144
|
-
|
145
|
-
rubygems_version: 2.5.1
|
146
|
+
rubygems_version: 3.1.6
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: A small library for parsing South African ID numbers
|