turkish_id 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +21 -7
- data/Gemfile +5 -2
- data/README.md +0 -7
- data/Rakefile +1 -0
- data/lib/turkish_id/version.rb +1 -1
- data/lib/turkish_id.rb +27 -51
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15a42720981e14cba171d93f4aae070f10142976
|
4
|
+
data.tar.gz: 578b38fcffb08ece46644abd56099be085764203
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7dba1b5eb2f5c166262a971f5af438f9b78046457ac39a7cc92f42ad7339878625a1a46e5689f5e2ba2afe63abcdf542575aad55abd26b1747e3c66710e59a4
|
7
|
+
data.tar.gz: 1b5f8d025248da5f83fd45b6a3a470f0fab9743c59ffe5e4538a4326045a77e2921706d7f795b33c126f6c420e82125b1583258af938eb2a2dbcac74c44b7ff8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
3
|
+
- ruby-head
|
4
|
+
- 2.5.1
|
5
|
+
- 2.4.4
|
6
|
+
- 2.3.7
|
7
|
+
- 2.2.10
|
8
|
+
- 2.1.8
|
4
9
|
- 1.9.3
|
5
|
-
|
6
|
-
- gem
|
10
|
+
before_install:
|
11
|
+
- gem update --system
|
12
|
+
- gem --version
|
7
13
|
- gem install bundler
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
|
15
|
+
env:
|
16
|
+
global:
|
17
|
+
- CC_TEST_REPORTER_ID=92655ba2c8b47200f80e996afb80c410b9491514845d414d7517108ad35a5178
|
18
|
+
before_script:
|
19
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
20
|
+
- chmod +x ./cc-test-reporter
|
21
|
+
- ./cc-test-reporter before-build
|
22
|
+
script:
|
23
|
+
- bundle exec rspec
|
24
|
+
after_script:
|
25
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile
CHANGED
@@ -3,5 +3,8 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in turkish_id.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem '
|
7
|
-
gem '
|
6
|
+
gem 'rake', group: :test
|
7
|
+
gem 'simplecov', group: :test, require: false
|
8
|
+
gem 'simplecov-console', group: :test, require: false
|
9
|
+
gem 'pry', '~> 0.10.3', group: :development, require: nil
|
10
|
+
|
data/README.md
CHANGED
@@ -41,13 +41,6 @@ $ turkish_id 10000000078
|
|
41
41
|
Your identification number is valid.
|
42
42
|
```
|
43
43
|
|
44
|
-
Use ```get_relatives``` method to check relatives:
|
45
|
-
|
46
|
-
```rb
|
47
|
-
identity_number.get_relatives(3)
|
48
|
-
=> ["10003000082", "10005999902", "10008999848"]
|
49
|
-
```
|
50
|
-
|
51
44
|
## Anatomy of the Turkish ID Number
|
52
45
|
|
53
46
|
The Turkish Identification Number consists of ```11``` digits.
|
data/Rakefile
CHANGED
data/lib/turkish_id/version.rb
CHANGED
data/lib/turkish_id.rb
CHANGED
@@ -1,78 +1,54 @@
|
|
1
1
|
require "turkish_id/version"
|
2
2
|
|
3
|
-
class String
|
4
|
-
def digitize
|
5
|
-
self.split('').map { |s| Integer(s) }
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
3
|
class TurkishId
|
4
|
+
attr_reader :id_number, :checksum
|
10
5
|
|
11
6
|
def initialize(id_number)
|
12
|
-
|
13
|
-
|
14
|
-
rescue
|
15
|
-
@id_number = '' # Suppress error & return false (eventually)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def core
|
21
|
-
@id_number.take(9)
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def self.get_checksum(id_core)
|
26
|
-
|
27
|
-
# Calculate the sums of odd and even digits
|
28
|
-
odds = id_core.values_at(0, 2, 4, 6, 8).reduce(:+)
|
29
|
-
evens = id_core.values_at(1, 3, 5, 7).reduce(:+)
|
30
|
-
|
31
|
-
# Generate checksum digits
|
32
|
-
d10 = ((odds * 7) - evens) % 10
|
33
|
-
d11 = (id_core.reduce(:+) + d10) % 10
|
34
|
-
|
35
|
-
[d10, d11]
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.add_checksum(id_core)
|
39
|
-
id_core + TurkishId.get_checksum(id_core)
|
7
|
+
@id_number = digitize(id_number)
|
8
|
+
@checksum = calculate_checksum(@id_number)
|
40
9
|
end
|
41
10
|
|
42
11
|
def is_valid?
|
43
|
-
id = @id_number #
|
12
|
+
id = @id_number # For brevity
|
44
13
|
|
45
|
-
#
|
14
|
+
# Early termination, bad length or first digit
|
46
15
|
return false if id.length != 11 || id.first == 0
|
47
16
|
|
48
|
-
#
|
49
|
-
|
17
|
+
# Calculate checksum if not already calculated
|
18
|
+
@checksum ||= calculate_checksum(id_number)
|
50
19
|
|
51
20
|
# Check if the tenth digit matches the algorithm
|
52
|
-
return false if id[9] !=
|
21
|
+
return false if id[9] != @checksum[0]
|
53
22
|
|
54
23
|
# Check if the eleventh digit matches the algorithm
|
55
|
-
return false if id[10] !=
|
24
|
+
return false if id[10] != @checksum[1]
|
56
25
|
|
57
26
|
true # All conditions met
|
58
27
|
end
|
59
28
|
|
60
|
-
|
29
|
+
private
|
61
30
|
|
62
|
-
|
31
|
+
def calculate_checksum(id_number)
|
32
|
+
# Calculate the sums of odd and even digits
|
33
|
+
odds = id_number.values_at(0, 2, 4, 6, 8).reduce(:+)
|
34
|
+
evens = id_number.values_at(1, 3, 5, 7).reduce(:+)
|
63
35
|
|
64
|
-
|
65
|
-
|
36
|
+
# Generate checksum digits
|
37
|
+
d10 = ((odds * 7) - evens) % 10
|
38
|
+
d11 = (id_number.take(9).reduce(:+) + d10) % 10
|
66
39
|
|
67
|
-
|
40
|
+
# Return checksum
|
41
|
+
[d10, d11]
|
42
|
+
rescue
|
43
|
+
[] # Unable to calculate checksum, initial value remains unchainged
|
44
|
+
end
|
68
45
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
46
|
+
def digitize(id_number)
|
47
|
+
# Narrow down scope of accepted types
|
48
|
+
return [] unless [String, Integer, Fixnum].include?(id_number.class)
|
73
49
|
|
74
|
-
#
|
75
|
-
|
50
|
+
# Convert string of numbers into an array of integers
|
51
|
+
id_number.to_s.split('').map { |s| Integer(s) }
|
76
52
|
end
|
77
53
|
|
78
54
|
end
|
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.3.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:
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.6.14
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Validate Turkish Identification Numbers and More!
|