za_id_number 2.0.0 → 2.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: 4ed3ce4b45b45da798697e7c5f48873752f53b6c12fc07ec985805d5acfe1190
4
- data.tar.gz: 7e14ac75dc6ab6a710be4d3dc9a261a066515d1ac53522fe4a2b2d4c510eeed8
3
+ metadata.gz: dd9d77d348b60523b50eb007e2f7d615b41e01291c8152427fc9aed33bbb9f97
4
+ data.tar.gz: 8f1edc87848ff3788b4039ca2f3492e133fac871a9237ced4bd99d6654638a2e
5
5
  SHA512:
6
- metadata.gz: 327d332579085ea13569812f310e577f280677726635e2df2493e545c4123aea8ba5b59408fc7ed0c40b97bcc9a6c3842a822c516fd352b5faaf0acb2bd8bf55
7
- data.tar.gz: f7706ab08495208b569734ad6910ae90e4abbc82255fec79b32c202f865d88f6d7fd2a12c1e0843745bc86ea6e2db89bd4a69f6ace55038c34f2b7412645b7e1
6
+ metadata.gz: eada6d8d9ef2b92ab1237946123821d49ddabe6ce0131133f7253b1c355c791e8d822b5e495be8266a903d0a00c77b7a8164ccacf8da46b47643283827aa6be2
7
+ data.tar.gz: eb5a7a4b1cfdcd9e97ce0637df59c7799d927b20c96b5033b95663f8a4c775d04aad1228346e977cb6c5940e1f65dac6ae90fa0c8cefa201d218a3c4bd6858ea
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.5.7
1
+ ruby 2.7.6
data/CHANGES ADDED
@@ -0,0 +1,25 @@
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.2.0] - 2023-04-05
13
+
14
+ ### Added
15
+
16
+ - Support for [ID numbers where the citizen is a refugee.](https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/South-Africa-TIN.pdf)
17
+
18
+ ## [2.1.0] - 2022-05-31
19
+
20
+ ### Added
21
+
22
+ - `to_s` for easier string interpolation
23
+ - Add equality operator `==` and `eql?` method
24
+ - Add `hash` method
25
+ - Make id number instances immutable
data/README.md CHANGED
@@ -12,7 +12,7 @@ A South African ID number is a 13-digit number which is defined by the following
12
12
 
13
13
  - The first 6 digits (`YYMMDD`) are based on your date of birth. **20 February 1992** is displayed as `920220`.
14
14
  - The next 4 digits (`SSSS`) are used to define your gender. Females are assigned numbers in the range 0000-4999 and males from 5000-9999.
15
- - The next digit (`C`) shows if you're a ZA citizen status, with 0 denoting that you were born a ZA citizen and 1 denoting that you're a permanent resident.
15
+ - The next digit (`C`) shows if you're a ZA citizen status, with 0 denoting that you were born a ZA citizen, 1 denoting that you're a permanent resident and 2 denoting that you're a refugee.
16
16
  - The last digit (`Z`) is a checksum digit – used to check that the number sequence is accurate using a set formula called the [Luhn algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm).
17
17
 
18
18
  The graphic below details the different sections of an ID number, based on the fictitious sequence `9202204720082`
@@ -77,6 +77,7 @@ id_num.male? # => false
77
77
  id_num.citizenship # => :za_citizen
78
78
  id_num.za_citizen? # => true
79
79
  id_num.permanent_resident? # => false
80
+ id_num.refugee? # => false
80
81
  ```
81
82
 
82
83
  Development
@@ -1,5 +1,5 @@
1
1
  class ZAIDNumber
2
2
  class Version
3
- VERSION = '2.0.0'
3
+ VERSION = '2.2.0'
4
4
  end
5
5
  end
data/lib/za_id_number.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'za_id_number/version'
2
4
  require 'luhn'
3
5
  require 'date'
@@ -6,14 +8,16 @@ class ZAIDNumber
6
8
  REQUIRED_ID_LENGTH = 13
7
9
  FEMALE_RANGE = (0..4999)
8
10
  MALE_RANGE = (5000..9999)
9
- CITIZENSHIP_RANGE = (0..1)
11
+ CITIZENSHIP_RANGE = (0..2)
10
12
  ZA_CITIZEN = 0
11
13
  PERMANENT_RESIDENT = 1
14
+ REFUGEE = 2
12
15
 
13
16
  attr_reader :id_number
17
+ alias to_s id_number
14
18
 
15
19
  def initialize(id_num)
16
- @id_number = id_num.to_s
20
+ @id_number = id_num.to_s.freeze
17
21
  end
18
22
 
19
23
  def valid?
@@ -41,7 +45,7 @@ class ZAIDNumber
41
45
  end
42
46
 
43
47
  def valid_citizenship?
44
- CITIZENSHIP_RANGE.include? @id_number[10].to_i
48
+ CITIZENSHIP_RANGE.include? citizenship_status
45
49
  end
46
50
 
47
51
  def date_of_birth
@@ -63,14 +67,39 @@ class ZAIDNumber
63
67
  end
64
68
 
65
69
  def citizenship
66
- za_citizen? ? :za_citizen : :permanent_resident
70
+ case citizenship_status
71
+ when ZA_CITIZEN then :za_citizen
72
+ when PERMANENT_RESIDENT then :permanent_resident
73
+ when REFUGEE then :refugee
74
+ end
67
75
  end
68
76
 
69
77
  def za_citizen?
70
- @id_number[10].to_i == ZA_CITIZEN
78
+ citizenship_status == ZA_CITIZEN
71
79
  end
72
80
 
73
81
  def permanent_resident?
74
82
  !za_citizen?
75
83
  end
84
+
85
+ def refugee?
86
+ citizenship_status == REFUGEE
87
+ end
88
+
89
+ def ==(other)
90
+ return false unless other.is_a?(ZAIDNumber)
91
+
92
+ return id_number == other.id_number
93
+ end
94
+ alias eql? ==
95
+
96
+ def hash
97
+ id_number.hash
98
+ end
99
+
100
+ private
101
+
102
+ def citizenship_status
103
+ @id_number[10].to_i
104
+ end
76
105
  end
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: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Fortuna
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2023-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,6 +112,7 @@ files:
112
112
  - ".rspec"
113
113
  - ".tool-versions"
114
114
  - ".travis.yml"
115
+ - CHANGES
115
116
  - CODE_OF_CONDUCT.md
116
117
  - Gemfile
117
118
  - LICENSE.txt
@@ -127,7 +128,7 @@ homepage: http://www.zero-one.io
127
128
  licenses:
128
129
  - MIT
129
130
  metadata: {}
130
- post_install_message:
131
+ post_install_message:
131
132
  rdoc_options: []
132
133
  require_paths:
133
134
  - lib
@@ -142,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  - !ruby/object:Gem::Version
143
144
  version: '0'
144
145
  requirements: []
145
- rubygems_version: 3.2.14
146
- signing_key:
146
+ rubygems_version: 3.1.6
147
+ signing_key:
147
148
  specification_version: 4
148
149
  summary: A small library for parsing South African ID numbers
149
150
  test_files: []