turkish_id 0.4.0 → 0.5.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 +4 -4
- data/README.md +32 -31
- data/lib/turkish_id.rb +1 -0
- data/lib/turkish_id/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4684fceace032af39d2544af388d2fdf0ab924a222c1a0e270d0e6aa85e017a
|
4
|
+
data.tar.gz: f60561764a5b5e51509a1347556ae0ef3783769e298362299506a4407839741b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b0430b78f2e136a35f3a260a5b392aecc73a288fd7aeea4c67030d95723977776abc12fc9ab72a13972598e2aaf320fe6cc5667419ce666b8298c8f560445f5
|
7
|
+
data.tar.gz: 8320d6109db78d527919c117be76a9ea52642f467f41ddcc80cd56f182859fbfbaf2aecf512958b7e1c04628aa68ac0770100c6a8573068c2314114dc0ecbde0
|
data/README.md
CHANGED
@@ -22,6 +22,8 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
### Validating ID Numbers
|
26
|
+
|
25
27
|
Create a new instance:
|
26
28
|
|
27
29
|
```rb
|
@@ -31,59 +33,38 @@ identity_number = TurkishId.new(10000000146)
|
|
31
33
|
Use ```is_valid?``` method to check validity:
|
32
34
|
|
33
35
|
```rb
|
34
|
-
identity_number.is_valid?
|
35
|
-
=> true
|
36
|
+
identity_number.is_valid? #=> true
|
36
37
|
```
|
37
38
|
|
38
39
|
Or use the command line executable:
|
39
40
|
|
40
41
|
```sh
|
41
|
-
$ turkish_id 10000000078
|
42
|
-
Your identification number is valid.
|
42
|
+
$ turkish_id 10000000078 #=> Your identification number is valid.
|
43
43
|
```
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
The Turkish Identification Number consists of ```11``` digits.
|
48
|
-
|
49
|
-
There are three conditions for a valid identification number:
|
50
|
-
|
51
|
-
1. ```d1 > 0```
|
52
|
-
2. ```d10 == ((d1 + d3 + d5 + d7 + d9) * 7 - (d2 + d4 + d6 + d8)) mod 10```
|
53
|
-
3. ```d11 == (d1 + d2 + d3 + d4 + d5 + d6 + d8 + d9 + d10) mod 10```
|
54
|
-
|
55
|
-
Where ```dn``` refers to the ```n-th``` digit of the identification number.
|
56
|
-
|
57
|
-
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.
|
58
|
-
|
59
|
-
|
60
|
-
## Generating Relatives
|
45
|
+
### Generating Relatives
|
61
46
|
|
62
47
|
You can generate ID numbers for your younger or elder relatives.
|
63
48
|
|
64
49
|
```rb
|
65
50
|
me = TurkishId.new(10000000146)
|
66
|
-
me.elder_relatives.take(5)
|
67
51
|
```
|
68
52
|
|
69
53
|
Calling `younger_relative` or `elder_relative` will return an Enumerable class.
|
70
54
|
|
71
55
|
```rb
|
72
|
-
me.elder_relative
|
73
|
-
#=> #<Enumerator:0x00007f9e629032d0>
|
56
|
+
me.elder_relative #=> #<Enumerator:0x00007f9e629032d0>
|
74
57
|
```
|
75
58
|
|
76
59
|
You can perform standard Enumerable operations on it.
|
77
60
|
|
78
61
|
```rb
|
79
|
-
me.elder_relative.first
|
80
|
-
|
81
|
-
#=> 10003000082
|
62
|
+
me.elder_relative.first #=> 10003000082
|
82
63
|
```
|
83
64
|
|
84
65
|
```rb
|
85
66
|
3.times do
|
86
|
-
puts me.elder_relative.next
|
67
|
+
puts me.elder_relative.next
|
87
68
|
end
|
88
69
|
|
89
70
|
#=> 10035998982
|
@@ -92,13 +73,30 @@ end
|
|
92
73
|
```
|
93
74
|
|
94
75
|
```rb
|
95
|
-
me.elder_relative.take(5)
|
96
|
-
|
97
|
-
#=> [10003000082, 10005999902, 10008999848, 10011999774, 10014999610]
|
76
|
+
me.elder_relative.take(5) #=> [10003000082, 10005999902, 10008999848, 10011999774, 10014999610]
|
98
77
|
```
|
99
78
|
|
100
79
|
And so on.
|
101
80
|
|
81
|
+
## Anatomy of the Turkish ID Number
|
82
|
+
|
83
|
+
The Turkish Identification Number consists of ```11``` digits.
|
84
|
+
|
85
|
+
There are three conditions for a valid identification number:
|
86
|
+
|
87
|
+
1. ```d1 > 0```
|
88
|
+
2. ```d10 == ((d1 + d3 + d5 + d7 + d9) * 7 - (d2 + d4 + d6 + d8)) mod 10```
|
89
|
+
3. ```d11 == (d1 + d2 + d3 + d4 + d5 + d6 + d8 + d9 + d10) mod 10```
|
90
|
+
|
91
|
+
Where ```dn``` refers to the ```n-th``` digit of the identification number.
|
92
|
+
|
93
|
+
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.
|
94
|
+
|
95
|
+
## Support
|
96
|
+
|
97
|
+
This gem is used in production and tested against the following Ruby versions: `ruby-head`, `2.5.1`, `2.4.4`, `2.3.7`, `2.2.10`, `2.1.8`, `1.9.3`. It has no dependencies and will likely work in any Ruby version above `1.9.3`. To make sure there are no breaking changes add it to your Gemfile using the pessimistic operator: `gem 'turkish_id', '~> 0.5.0'`.
|
98
|
+
|
99
|
+
|
102
100
|
## Development
|
103
101
|
|
104
102
|
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.
|
@@ -115,9 +113,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
115
113
|
|
116
114
|
Bug reports and pull requests are welcome on GitHub at https://github.com/krmbzds/turkish_id.
|
117
115
|
|
116
|
+
## Is it any good?
|
117
|
+
|
118
|
+
Yes.
|
118
119
|
|
119
120
|
## License
|
120
121
|
|
121
|
-
Copyright © 2015 Kerem Bozdaş
|
122
|
+
Copyright © 2015 [Kerem Bozdaş](http://kerembozdas.com/)
|
122
123
|
|
123
124
|
This gem is available under the terms of the [MIT License](https://github.com/krmbzds/turkish_id/blob/master/LICENSE.txt).
|
data/lib/turkish_id.rb
CHANGED
data/lib/turkish_id/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turkish_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kerem Bozdas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Validate Turkish Identification Numbers and More!
|
14
14
|
email:
|