kuwaiti_civil_id 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a21ea678cf307710bed0713ca346724682c76cf76c3f263cb6c1c34f19c9c607
4
+ data.tar.gz: a41945e7cd13c5439c8fa85961373946e377febe33abd8be3e2058a7401df435
5
+ SHA512:
6
+ metadata.gz: 59ddf0c651fb4276928f8c1bb7b91ed11c844897fa27ab513177ab9df3b86c698c9ec5cd22af6d5285c2b215dad131bfce78b9a57ff9e2214707ddbfec37fdb4
7
+ data.tar.gz: d15297a93038d4f499bab7b9d0c1dce309fcd58159669eaceba5a87514fafe5f7054a790410e5d5eaeb50ab0590aa93344384531c909fd7f3d21df0928349717
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2026-06-05
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "kuwaiti_civil_id" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["info@kaffeinated.dev"](mailto:"info@kaffeinated.dev").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Abdullah Esmail
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.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # KuwaitiCivilId
2
+
3
+ This gem provides a simple interface to validate and extract information from Kuwaiti Civil ID numbers. It checks the validity of the ID number and extracts the birth date.
4
+
5
+ ## Installation
6
+
7
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```bash
12
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```bash
18
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'kuwaiti_civil_id'
25
+ KuwaitiCivilId::CivilIdValidator.valid?('123456789012')
26
+ #=> false
27
+
28
+ # assuming '295020101234' is a valid Kuwaiti Civil ID number
29
+ KuwaitiCivilId::BirthdateExtractor.extract('295020101234')
30
+ #=> #<Date: 1995-02-01>
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kaffeinated-dev/kuwaiti-civil-id-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/kaffeinated-dev/kuwaiti-civil-id-ruby/blob/main/CODE_OF_CONDUCT.md).
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the KuwaitiCivilId project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kaffeinated-dev/kuwaiti-civil-id-ruby/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KuwaitiCivilId
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "kuwaiti_civil_id/version"
4
+
5
+ module KuwaitiCivilId
6
+ class Error < StandardError; end
7
+ class InvalidCivilIdError < Error; end
8
+
9
+ class CivilIdValidator
10
+ def self.valid?(id_number)
11
+ return false unless id_number.to_s.match?(/\A\d{12}$\z/)
12
+
13
+ digits = id_number.to_s.chars.map(&:to_i)
14
+ checksum = digits.pop
15
+ coefficients = [2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
16
+ digits.zip(coefficients).sum { |d, c| d * c }
17
+ calculated_checksum = 11 - (sun % 11)
18
+ calculated_checksum == checksum
19
+ end
20
+ end
21
+
22
+ class BirthdateExtractor
23
+ def self.extract(id_number)
24
+ raise InvalidCivilIdError unless CivilIdValidator.valid?(id_number)
25
+
26
+ century = id_number[0].to_i
27
+ year = id_number[1..2].to_i
28
+ month = id_number[3..4].to_i
29
+ day = id_number[5..6].to_i
30
+
31
+ century_prefix = case century
32
+ when 2 then "19"
33
+ when 3 then "20"
34
+ else return nil
35
+ end
36
+
37
+ year = "#{century_prefix}#{year}".to_i
38
+ Date.new(year, month, day)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ module KuwaitiCivilId
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuwaiti_civil_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdullah Esmail
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Provides functionality to validate the format of Kuwaiti Civil ID numbers
13
+ and extract information such as birth date.
14
+ email:
15
+ - info@kaffeinated.dev
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - CODE_OF_CONDUCT.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/kuwaiti_civil_id.rb
26
+ - lib/kuwaiti_civil_id/version.rb
27
+ - sig/kuwaiti_civil_id.rbs
28
+ homepage: https://github.com/kaffeinated-dev/kuwaiti-civil-id-ruby
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ homepage_uri: https://github.com/kaffeinated-dev/kuwaiti-civil-id-ruby
33
+ source_code_uri: https://github.com/kaffeinated-dev/kuwaiti-civil-id-ruby
34
+ changelog_uri: https://github.com/kaffeinated-dev/kuwaiti-civil-id-ruby/blob/main/CHANGELOG.md
35
+ rubygems_mfa_required: 'true'
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.2.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 4.0.13
51
+ specification_version: 4
52
+ summary: A Ruby gem for validating and parsing Kuwaiti Civil ID numbers.
53
+ test_files: []