turkish_id 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -3
- data/Gemfile +3 -1
- data/README.md +5 -5
- data/Rakefile +3 -2
- data/bin/console +1 -0
- data/bin/turkish_id +3 -3
- data/lib/turkish_id.rb +15 -16
- data/lib/turkish_id/version.rb +3 -1
- data/turkish_id.gemspec +3 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f2ce68dae19376b6afae68d92f079c60661ef424d26a58f7a201c43893860dc
|
4
|
+
data.tar.gz: 3370d7423c4cd7b60df5143f6e890242e5381b7d7fe7a0224d9bf3d25950aa8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b87c07e37a6e77264a43ab52e218c6419b859d6daa79bfcfe38cb35b379fd39f25bf447576fbdaf3b3c43bafca4dca83639ffa485e2bd1e34ddac8b87398c962
|
7
|
+
data.tar.gz: fd1974ed82dd65682b1f5a09a265dc020282551b2be4e53c5eca23bdf5f28bee0c18f6c882c5ca3f40b0501ebd6750c16394f80ae4f7d343d3b06eb16271ecf5
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.7.1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -30,10 +30,10 @@ Create a new instance:
|
|
30
30
|
identity_number = TurkishId.new(10000000146)
|
31
31
|
```
|
32
32
|
|
33
|
-
Use ```
|
33
|
+
Use ```valid?``` method to check validity:
|
34
34
|
|
35
35
|
```rb
|
36
|
-
identity_number.
|
36
|
+
identity_number.valid? #=> true
|
37
37
|
```
|
38
38
|
|
39
39
|
Or use the command line executable:
|
@@ -98,9 +98,9 @@ Remember that a valid identification number does not imply the existence of an I
|
|
98
98
|
|
99
99
|
This gem is used in production and tested against the following Ruby versions:
|
100
100
|
|
101
|
-
- ✅ `2.
|
102
|
-
- ✅ `2.
|
103
|
-
- ⏳ `2.
|
101
|
+
- ✅ `2.7.1` (stable)
|
102
|
+
- ✅ `2.6.6` (stable)
|
103
|
+
- ⏳ `2.5.8` (security maintenance)
|
104
104
|
|
105
105
|
## Development
|
106
106
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/bin/turkish_id
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
5
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
@@ -22,11 +22,11 @@ end
|
|
22
22
|
|
23
23
|
def validate_id(id_number)
|
24
24
|
identity_number = TurkishId.new(id_number)
|
25
|
-
print_result(identity_number.
|
25
|
+
print_result(identity_number.valid?)
|
26
26
|
end
|
27
27
|
|
28
28
|
def print_result(result)
|
29
|
-
STDOUT.puts "Your identification number is #{
|
29
|
+
STDOUT.puts "Your identification number is #{result ? 'valid' : 'invalid'}."
|
30
30
|
end
|
31
31
|
|
32
32
|
def print_help
|
data/lib/turkish_id.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'turkish_id/version'
|
2
4
|
|
3
5
|
class TurkishId
|
@@ -10,17 +12,11 @@ class TurkishId
|
|
10
12
|
@younger_relative = generate_relatives(@id_number, :down)
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
|
15
|
-
return false if @id_number.
|
16
|
-
|
17
|
-
# Calculate checksum if not already calculated
|
18
|
-
@checksum ||= calculate_checksum(@id_number)
|
19
|
-
|
20
|
-
# Check if tenth or eleventh digits match the algorithm
|
21
|
-
return false if @id_number[9] != @checksum[0] || @id_number[10] != @checksum[1]
|
15
|
+
def valid?
|
16
|
+
return false if @id_number.length != 11 || @id_number.first.zero?
|
17
|
+
return false if @id_number.values_at(9, 10) != @checksum ||= calculate_checksum(@id_number)
|
22
18
|
|
23
|
-
true
|
19
|
+
true
|
24
20
|
end
|
25
21
|
|
26
22
|
private
|
@@ -36,7 +32,7 @@ class TurkishId
|
|
36
32
|
|
37
33
|
# Return checksum
|
38
34
|
[d10, d11]
|
39
|
-
rescue
|
35
|
+
rescue StandardError
|
40
36
|
[]
|
41
37
|
end
|
42
38
|
|
@@ -47,7 +43,7 @@ class TurkishId
|
|
47
43
|
|
48
44
|
def next_relative(id_array, direction)
|
49
45
|
tree = { up: 1, down: -1 }
|
50
|
-
get_core(id_array) +
|
46
|
+
get_core(id_array) + 29_999 * tree[direction]
|
51
47
|
end
|
52
48
|
|
53
49
|
def generate_relatives(id_array, direction)
|
@@ -55,23 +51,26 @@ class TurkishId
|
|
55
51
|
id = join_num(id_array)
|
56
52
|
loop do
|
57
53
|
id = next_relative(id, direction)
|
58
|
-
break unless id.between?(
|
54
|
+
break unless id.between?(100_000_001, 999_999_999)
|
55
|
+
|
59
56
|
y << append_checksum(id)
|
60
57
|
end
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
64
61
|
def get_id_array(id)
|
65
|
-
split_num(Integer(id))
|
62
|
+
split_num(Integer(id))
|
63
|
+
rescue StandardError
|
64
|
+
[]
|
66
65
|
end
|
67
66
|
|
68
67
|
def split_num(num)
|
69
68
|
n = Math.log10(num).floor
|
70
|
-
(0..n).map{ |i| (num / 10
|
69
|
+
(0..n).map { |i| (num / 10**(n - i)) % 10 }
|
71
70
|
end
|
72
71
|
|
73
72
|
def join_num(id_array)
|
74
|
-
id_array.inject{ |a, i| a * 10 + i }
|
73
|
+
id_array.inject { |a, i| a * 10 + i }
|
75
74
|
end
|
76
75
|
|
77
76
|
def get_core(id_array)
|
data/lib/turkish_id/version.rb
CHANGED
data/turkish_id.gemspec
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kerem Bozdas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Validate Turkish Identification Numbers and More!
|
14
14
|
email:
|
@@ -37,7 +37,7 @@ homepage: https://github.com/krmbzds/turkish_id
|
|
37
37
|
licenses:
|
38
38
|
- MIT
|
39
39
|
metadata: {}
|
40
|
-
post_install_message:
|
40
|
+
post_install_message:
|
41
41
|
rdoc_options: []
|
42
42
|
require_paths:
|
43
43
|
- lib
|
@@ -53,8 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
rubygems_version: 3.
|
57
|
-
signing_key:
|
56
|
+
rubygems_version: 3.1.3
|
57
|
+
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: Validate Turkish Identification Numbers and More!
|
60
60
|
test_files: []
|