turkish_id 0.5.0 → 1.3.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/.ruby-version +1 -1
- data/.travis.yml +6 -11
- data/Gemfile +5 -4
- data/README.md +22 -9
- data/Rakefile +4 -3
- data/bin/console +4 -7
- data/bin/turkish_id +3 -3
- data/lib/turkish_id.rb +16 -17
- data/lib/turkish_id/version.rb +3 -1
- data/turkish_id.gemspec +3 -2
- metadata +6 -7
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
@@ -1,17 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.3.7
|
7
|
-
- 2.2.10
|
8
|
-
- 2.1.8
|
9
|
-
- 1.9.3
|
3
|
+
- 2.7.1
|
4
|
+
- 2.6.6
|
5
|
+
- 2.5.8
|
10
6
|
before_install:
|
11
|
-
- gem update --system
|
12
|
-
- gem --version
|
13
|
-
- gem install bundler
|
14
|
-
|
7
|
+
- 'gem update --system'
|
8
|
+
- 'gem --version'
|
9
|
+
- 'gem install bundler'
|
15
10
|
env:
|
16
11
|
global:
|
17
12
|
- CC_TEST_REPORTER_ID=92655ba2c8b47200f80e996afb80c410b9491514845d414d7517108ad35a5178
|
data/Gemfile
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in turkish_id.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
8
|
group :test do
|
9
|
+
gem 'bundler'
|
7
10
|
gem 'rake'
|
8
|
-
gem '
|
9
|
-
gem '
|
10
|
-
gem 'simplecov', '~> 0.16.1'
|
11
|
-
gem 'simplecov-console', '~> 0.4.2'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'simplecov'
|
12
13
|
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Turkish ID
|
1
|
+
# Turkish ID 🔖
|
2
2
|
|
3
3
|
[](https://travis-ci.org/krmbzds/turkish_id) [](https://github.com/krmbzds/turkish_id) [](https://rubygems.org/gems/turkish_id) [](https://rubygems.org/gems/turkish_id) [](https://codeclimate.com/github/krmbzds/turkish_id) [](https://codeclimate.com/github/krmbzds/turkish_id/coverage)
|
4
4
|
|
@@ -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:
|
@@ -94,24 +94,31 @@ Remember that a valid identification number does not imply the existence of an I
|
|
94
94
|
|
95
95
|
## Support
|
96
96
|
|
97
|
-
|
97
|
+
#### Ruby Versions Tested Against
|
98
98
|
|
99
|
+
This gem is used in production and tested against the following Ruby versions:
|
100
|
+
|
101
|
+
- ✅ `2.7.1` (stable)
|
102
|
+
- ✅ `2.6.6` (stable)
|
103
|
+
- ⏳ `2.5.8` (security maintenance)
|
99
104
|
|
100
105
|
## Development
|
101
106
|
|
102
107
|
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.
|
103
108
|
|
104
|
-
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]
|
109
|
+
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][RubyGems].
|
105
110
|
|
106
111
|
## Contributing
|
107
112
|
|
108
|
-
1. Fork
|
113
|
+
1. [Fork the repository][Fork]
|
109
114
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
110
115
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
111
116
|
4. Push to the branch (`git push origin my-new-feature`)
|
112
117
|
5. Create new Pull Request
|
113
118
|
|
114
|
-
|
119
|
+
### Donations ❤️
|
120
|
+
|
121
|
+
You can donate me at [Liberapay][Donation]. Thanks! ☕️
|
115
122
|
|
116
123
|
## Is it any good?
|
117
124
|
|
@@ -119,6 +126,12 @@ Yes.
|
|
119
126
|
|
120
127
|
## License
|
121
128
|
|
122
|
-
Copyright ©
|
129
|
+
Copyright © 2019 [Kerem Bozdas][Personal Webpage]
|
130
|
+
|
131
|
+
This gem is available under the terms of the [MIT License][License].
|
123
132
|
|
124
|
-
|
133
|
+
[Donation]: https://liberapay.com/krmbzds/donate
|
134
|
+
[Fork]: https://github.com/krmbzds/turkish_id/fork
|
135
|
+
[License]: https://kerem.mit-license.org
|
136
|
+
[Personal Webpage]: https://kerembozdas.com
|
137
|
+
[RubyGems]: https://rubygems.org
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'turkish_id'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
8
9
|
|
9
|
-
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
10
|
+
require 'irb'
|
14
11
|
IRB.start
|
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,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'turkish_id/version'
|
2
4
|
|
3
5
|
class TurkishId
|
4
6
|
attr_reader :id_number, :checksum, :elder_relative, :younger_relative
|
@@ -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:
|
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,9 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
|
57
|
-
|
58
|
-
signing_key:
|
56
|
+
rubygems_version: 3.1.3
|
57
|
+
signing_key:
|
59
58
|
specification_version: 4
|
60
59
|
summary: Validate Turkish Identification Numbers and More!
|
61
60
|
test_files: []
|