za_id_number 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5a9409a4cbf5d9fecfd49c0f75a5edc20927d27
4
+ data.tar.gz: 8d8a5ccd8bdd39e1badb5d9a20ae75e222d20cdd
5
+ SHA512:
6
+ metadata.gz: 35008d2b1410cf41fb9b8d870c67f71b3088be38013d03f7f14ec269459f1de56c9920051bc941c69b01e507f8a122568fe619ec82175db530400b6831f51f26
7
+ data.tar.gz: 6cbca82db59d804a7edf81a1e1f3aec60e2a0ee94e053e0e0f38cb6937e7055fa047f99d6915df5347834643d27ff83a95cf7abffa92533af92eb6043b409ac9
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.7
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at gabriel@zero-one.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in za_id_number.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Gabriel Fortuna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,97 @@
1
+ ZAIDNumber
2
+ ==========
3
+
4
+ A simple gem for working with South African ID numbers.
5
+
6
+ Details
7
+ =======
8
+
9
+ South African ID numbers have a fair amount of information serialized into them, including an all important checksum number. The below information is taken from a page deep within [The Western Cape Government's website](https://www.westerncape.gov.za/general-publication/decoding-your-south-african-id-number-0).
10
+
11
+ A South African ID number is a 13-digit number which is defined by the following format: `YYMMDDSSSSCAZ`.
12
+
13
+ - The first 6 digits (`YYMMDD`) are based on your date of birth. **20 February 1992** is displayed as `920220`.
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.
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
+
18
+ The graphic below details the different sections of an ID number, based on the fictitious sequence `9202204720082`
19
+
20
+ ![ZA ID Number Infographic](za-id-number.png)
21
+
22
+ Installation
23
+ ------------
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'za_id_number'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ ```
34
+ $ bundle
35
+ ```
36
+
37
+ Or install it yourself as:
38
+
39
+ ```
40
+ $ gem install za_id_number
41
+ ```
42
+
43
+ Usage
44
+ -----
45
+
46
+ Given a valid ZA ID Number, `7501151234085`, the following interface is available:
47
+
48
+ ```ruby
49
+ id_number = ZAIDNumber.new('7501151234085') # => #<ZAIDNumber:0x00d40 @id_number="75011...
50
+ ```
51
+
52
+ ### Validation checks
53
+
54
+ ```ruby
55
+ id_num.has_valid_length? # => true
56
+ id_num.has_only_digits? # => true
57
+ id_num.has_valid_date? # => true
58
+ id_num.has_valid_citizenship? # => true
59
+ id_num.has_valid_checksum? # => true
60
+ ```
61
+
62
+ Or, roll up all those validation checks into one call:
63
+
64
+ ```ruby
65
+ id_number.valid? # => true
66
+ ```
67
+
68
+ ### Information about the data embedded in the ID Number
69
+
70
+ You can also use this gem to extract information embedded in the ID number as per the infographic above.
71
+
72
+ ```ruby
73
+ id_num.date_of_birth # => #<Date: 1975-01-15 ((2442428j,0s,0n),+0s,2299161j)>
74
+ id_num.gender # => :f
75
+ id_num.female? # => true
76
+ id_num.male? # => false
77
+ id_num.citizenship # => :za_citizen
78
+ id_num.za_citizen? # => true
79
+ id_num.permanent_resident? # => false
80
+ ```
81
+
82
+ Development
83
+ -----------
84
+
85
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
86
+
87
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
88
+
89
+ Contributing
90
+ ------------
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zero-one-software/za_id_number. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
93
+
94
+ License
95
+ -------
96
+
97
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "za_id_number"
5
+ require "awesome_print"
6
+
7
+ def reload!
8
+ files = $LOADED_FEATURES.select { |feat| feat =~ /za_id_number/ }
9
+ files.each { |file| load file }
10
+ "reloaded."
11
+ end
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ require "pry"
15
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,75 @@
1
+ require 'za_id_number/version'
2
+ require 'luhn'
3
+
4
+ class ZAIDNumber
5
+ REQUIRED_ID_LENGTH = 13
6
+ FEMALE_RANGE = (0..4999)
7
+ MALE_RANGE = (5000..9999)
8
+ CITIZENSHIP_RANGE = (0..1)
9
+ ZA_CITIZEN = 0
10
+ PERMANENT_RESIDENT = 1
11
+
12
+ attr_reader :id_number
13
+
14
+ def initialize(id_num)
15
+ @id_number = id_num.to_s
16
+ end
17
+
18
+ def valid?
19
+ has_valid_length? &&
20
+ has_only_digits? &&
21
+ has_valid_date? &&
22
+ has_valid_citizenship? &&
23
+ has_valid_checksum?
24
+ end
25
+
26
+ def has_valid_checksum?
27
+ Luhn.valid? @id_number
28
+ end
29
+
30
+ def has_valid_length?
31
+ @id_number.length == REQUIRED_ID_LENGTH
32
+ end
33
+
34
+ def has_only_digits?
35
+ @id_number.to_s.gsub(/\D*/, '') == @id_number.to_s
36
+ end
37
+
38
+ def has_valid_date?
39
+ date_of_birth ? true : false
40
+ end
41
+
42
+ def has_valid_citizenship?
43
+ CITIZENSHIP_RANGE.include? @id_number[10].to_i
44
+ end
45
+
46
+ def date_of_birth
47
+ Date.parse("#{@id_number[0..1]}-#{@id_number[2..3]}-#{@id_number[4..5]}")
48
+ rescue ArgumentError
49
+ nil
50
+ end
51
+
52
+ def gender
53
+ female? ? :f : :m
54
+ end
55
+
56
+ def female?
57
+ FEMALE_RANGE.include? @id_number[6..9].to_i
58
+ end
59
+
60
+ def male?
61
+ !female?
62
+ end
63
+
64
+ def citizenship
65
+ za_citizen? ? :za_citizen : :permanent_resident
66
+ end
67
+
68
+ def za_citizen?
69
+ @id_number[10].to_i == ZA_CITIZEN
70
+ end
71
+
72
+ def permanent_resident?
73
+ !za_citizen?
74
+ end
75
+ end
@@ -0,0 +1,5 @@
1
+ class ZAIDNumber
2
+ class Version
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
Binary file
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'za_id_number/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "za_id_number"
9
+ spec.version = ZAIDNumber::Version::VERSION
10
+ spec.authors = ["Gabriel Fortuna"]
11
+ spec.email = ["gabriel@zero-one.io"]
12
+
13
+ spec.summary = "A small library for parsing South African ID numbers"
14
+ spec.description = "A small library for parsing, validating, and providing information on South African ID numbers"
15
+ spec.homepage = "http://www.zero-one.io"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against " \
24
+ # "public gem pushes."
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.13'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'pry', '~> 0.11.3'
38
+ spec.add_development_dependency 'awesome_print', '~> 1.8'
39
+
40
+ spec.add_dependency 'luhn', '~> 1.0', '>= 1.0.2'
41
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: za_id_number
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Fortuna
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: luhn
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.0.2
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.0'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.0.2
103
+ description: A small library for parsing, validating, and providing information on
104
+ South African ID numbers
105
+ email:
106
+ - gabriel@zero-one.io
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - ".gitignore"
112
+ - ".rspec"
113
+ - ".travis.yml"
114
+ - CODE_OF_CONDUCT.md
115
+ - Gemfile
116
+ - LICENSE.txt
117
+ - README.md
118
+ - Rakefile
119
+ - bin/console
120
+ - bin/setup
121
+ - lib/za_id_number.rb
122
+ - lib/za_id_number/version.rb
123
+ - za-id-number.png
124
+ - za_id_number.gemspec
125
+ homepage: http://www.zero-one.io
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A small library for parsing South African ID numbers
149
+ test_files: []