turkish_id 0.1.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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +5 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bin/turkish_id +18 -0
- data/lib/turkish_id/version.rb +3 -0
- data/lib/turkish_id.rb +33 -0
- data/turkish_id.gemspec +25 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac00acf5d67426d22aec34b35e3c5115ee54cc39
|
4
|
+
data.tar.gz: 10f764a1bc0a2fed3dbda9716a89ce517211527c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88991714f712feba40571e886f33d52165711a783cdc8c13f427e1deb38307bc6d55a467327327bb3537d77d7cd711276608404fa8437506ffb3b939dfd4bf25
|
7
|
+
data.tar.gz: 2f20697b59ad19e97394e35b695aa55f77fd39cb351771859383ff960433e3165866740d888caa7bf922801436ac40923adb971a01ad2f5df53e58f6fe971521
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
turkish_id
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Kerem Bozdas
|
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,70 @@
|
|
1
|
+
# Turkish ID [](https://travis-ci.org/krmbzds/turkish_id) [](https://gemnasium.com/krmbzds/turkish_id) [](https://codeclimate.com/github/krmbzds/turkish_id) [](https://codeclimate.com/github/krmbzds/turkish_id/coverage)
|
2
|
+
|
3
|
+
This gem provides methods to validate Turkish Identification Numbers.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'turkish_id'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install turkish_id
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Create a new instance:
|
25
|
+
```rb
|
26
|
+
identity_number = TurkishId.new('10000000146')
|
27
|
+
```
|
28
|
+
Use ```is_valid?``` method to check validity:
|
29
|
+
|
30
|
+
```rb
|
31
|
+
identity_number.is_valid?
|
32
|
+
=> true
|
33
|
+
```
|
34
|
+
|
35
|
+
## Anatomy of the Turkish ID Number
|
36
|
+
|
37
|
+
The Turkish Identification Number consists of ```11``` digits.
|
38
|
+
|
39
|
+
There are three conditions for a valid identification number:
|
40
|
+
|
41
|
+
1. ```d1 > 0```
|
42
|
+
2. ```d10 == ((d1 + d3 + d5 + d7 + d9) * 7 - (d2 + d4 + d6 + d8)) mod 10```
|
43
|
+
3. ```d11 == (d1 + d2 + d3 + d4 + d5 + d6 + d8 + d9 + d10) mod 10```
|
44
|
+
|
45
|
+
Where ```dn``` refers to the ```n-th``` digit of the identification number.
|
46
|
+
|
47
|
+
Remember that a valid identification number does not imply the existence of an ID. It could only be used as a preliminary check e.g. before querying a government website. This is very similar to credit card validation.
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
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.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( http://github.com/krmbzds/turkish_id/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/krmbzds/turkish_id.
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
Copyright © 2015 Kerem Bozdaş
|
69
|
+
|
70
|
+
This gem is available under the terms of the [MIT License](https://github.com/krmbzds/turkish_id/blob/master/LICENSE.txt).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "turkish_id"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/turkish_id
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require 'turkish_id'
|
8
|
+
|
9
|
+
print "Enter your 11 digit id number to validate: "
|
10
|
+
|
11
|
+
begin
|
12
|
+
identity_number = TurkishId.new(gets.chomp)
|
13
|
+
valid = identity_number.is_valid?
|
14
|
+
rescue
|
15
|
+
puts "Your identification number is invalid."
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "Your identification number is valid." if valid
|
data/lib/turkish_id.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "turkish_id/version"
|
2
|
+
|
3
|
+
class TurkishId
|
4
|
+
|
5
|
+
def initialize(id_number)
|
6
|
+
begin
|
7
|
+
# Convert string into array of integers
|
8
|
+
@id_number = id_number.split('').map { |s| Integer(s) }
|
9
|
+
rescue
|
10
|
+
@id_number = '' # Suppress error & return false (eventually)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_valid?
|
15
|
+
id = @id_number # +1 brevity point
|
16
|
+
|
17
|
+
# Early elimination, bad length or first digit
|
18
|
+
return false if id.length != 11 || id.first == 0
|
19
|
+
|
20
|
+
# Calculate the sums of odd and even digits
|
21
|
+
odds = id.values_at(0, 2, 4, 6, 8).reduce(:+)
|
22
|
+
evens = id.values_at(1, 3, 5, 7).reduce(:+)
|
23
|
+
|
24
|
+
# Check if the tenth digit matches the algorithm
|
25
|
+
return false if id[9] != ((odds * 7) - evens) % 10
|
26
|
+
|
27
|
+
# Check if the eleventh digit matches the algorithm
|
28
|
+
return false if id[10] != id[0..9].reduce(:+) % 10
|
29
|
+
|
30
|
+
return true # All conditions met
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/turkish_id.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'turkish_id/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'turkish_id'
|
8
|
+
spec.version = TurkishId::VERSION
|
9
|
+
spec.authors = ['Kerem Bozdas']
|
10
|
+
spec.email = ['krmbzds.github@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Validate Turkish Identification Numbers'
|
13
|
+
spec.description = 'Validate Turkish Identification Numbers'
|
14
|
+
spec.homepage = 'https://github.com/krmbzds/turkish_id'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = ['turkish_id']
|
20
|
+
spec.require_paths = ['lib', 'lib/turkish_id']
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turkish_id
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kerem Bozdas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-27 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Validate Turkish Identification Numbers
|
56
|
+
email:
|
57
|
+
- krmbzds.github@gmail.com
|
58
|
+
executables:
|
59
|
+
- turkish_id
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".ruby-gemset"
|
66
|
+
- ".ruby-version"
|
67
|
+
- ".travis.yml"
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- bin/turkish_id
|
75
|
+
- lib/turkish_id.rb
|
76
|
+
- lib/turkish_id/version.rb
|
77
|
+
- turkish_id.gemspec
|
78
|
+
homepage: https://github.com/krmbzds/turkish_id
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
- lib/turkish_id
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Validate Turkish Identification Numbers
|
103
|
+
test_files: []
|