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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 981b26b23fc03c750903f2300a20fbc668f98db0d04da9bcceb029bb43117a59
4
- data.tar.gz: 9ef99c3d80572269d44c43b7896c367512e51bb54a813b15bf5c788702e35895
3
+ metadata.gz: 9f2ce68dae19376b6afae68d92f079c60661ef424d26a58f7a201c43893860dc
4
+ data.tar.gz: 3370d7423c4cd7b60df5143f6e890242e5381b7d7fe7a0224d9bf3d25950aa8b
5
5
  SHA512:
6
- metadata.gz: e5ea1ef848cb15b940cab3bdd1ba538abf9926bf8f1ddc229d2a2110786965f0921a240243b852ea1c43c3f391737ab758c57b12f0ebdf8b010b901b0d14f4b3
7
- data.tar.gz: 35cb558319958f2931f12e67601b765b793d2b2eb6c5ca2af01e22ae71b18c3e069e3068e8a545e32155665d53d5895b0a9e1e358da8b9bf68bd278a5144db17
6
+ metadata.gz: b87c07e37a6e77264a43ab52e218c6419b859d6daa79bfcfe38cb35b379fd39f25bf447576fbdaf3b3c43bafca4dca83639ffa485e2bd1e34ddac8b87398c962
7
+ data.tar.gz: fd1974ed82dd65682b1f5a09a265dc020282551b2be4e53c5eca23bdf5f28bee0c18f6c882c5ca3f40b0501ebd6750c16394f80ae4f7d343d3b06eb16271ecf5
@@ -1 +1 @@
1
- ruby-2.6.5
1
+ ruby-2.7.1
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.6.5
4
- - 2.5.7
5
- - 2.4.9
3
+ - 2.7.1
4
+ - 2.6.6
5
+ - 2.5.8
6
6
  before_install:
7
7
  - 'gem update --system'
8
8
  - 'gem --version'
data/Gemfile CHANGED
@@ -1,11 +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
7
- gem 'rake'
8
9
  gem 'bundler'
10
+ gem 'rake'
9
11
  gem 'rspec'
10
12
  gem 'simplecov'
11
13
  end
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 ```is_valid?``` method to check validity:
33
+ Use ```valid?``` method to check validity:
34
34
 
35
35
  ```rb
36
- identity_number.is_valid? #=> true
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.6.5` (stable)
102
- - ✅ `2.5.7` (stable)
103
- - ⏳ `2.4.9` (security maintenance)
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
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
- task :default => :spec
6
-
7
+ task default: :spec
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'turkish_id'
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
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.is_valid?)
25
+ print_result(identity_number.valid?)
26
26
  end
27
27
 
28
28
  def print_result(result)
29
- STDOUT.puts "Your identification number is #{ result ? 'valid' : 'invalid' }."
29
+ STDOUT.puts "Your identification number is #{result ? 'valid' : 'invalid'}."
30
30
  end
31
31
 
32
32
  def print_help
@@ -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 is_valid?
14
- # Early termination, bad length or first digit
15
- return false if @id_number.length != 11 || @id_number.first == 0
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 # All conditions met
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) + 29999 * tree[direction]
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?(100000001, 999999999)
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)) rescue []
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 ** (n - i)) % 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)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class TurkishId
2
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
3
5
  end
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'turkish_id/version'
5
6
 
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.2.0
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: 2019-11-17 00:00:00.000000000 Z
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.0.6
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: []