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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4684fceace032af39d2544af388d2fdf0ab924a222c1a0e270d0e6aa85e017a
4
- data.tar.gz: f60561764a5b5e51509a1347556ae0ef3783769e298362299506a4407839741b
3
+ metadata.gz: 9f2ce68dae19376b6afae68d92f079c60661ef424d26a58f7a201c43893860dc
4
+ data.tar.gz: 3370d7423c4cd7b60df5143f6e890242e5381b7d7fe7a0224d9bf3d25950aa8b
5
5
  SHA512:
6
- metadata.gz: 3b0430b78f2e136a35f3a260a5b392aecc73a288fd7aeea4c67030d95723977776abc12fc9ab72a13972598e2aaf320fe6cc5667419ce666b8298c8f560445f5
7
- data.tar.gz: 8320d6109db78d527919c117be76a9ea52642f467f41ddcc80cd56f182859fbfbaf2aecf512958b7e1c04628aa68ac0770100c6a8573068c2314114dc0ecbde0
6
+ metadata.gz: b87c07e37a6e77264a43ab52e218c6419b859d6daa79bfcfe38cb35b379fd39f25bf447576fbdaf3b3c43bafca4dca83639ffa485e2bd1e34ddac8b87398c962
7
+ data.tar.gz: fd1974ed82dd65682b1f5a09a265dc020282551b2be4e53c5eca23bdf5f28bee0c18f6c882c5ca3f40b0501ebd6750c16394f80ae4f7d343d3b06eb16271ecf5
@@ -1 +1 @@
1
- ruby-2.5.1
1
+ ruby-2.7.1
@@ -1,17 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - ruby-head
4
- - 2.5.1
5
- - 2.4.4
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 'bundler', '~> 1.10'
9
- gem 'rspec', '~> 3.4'
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
  [![Build Status](https://travis-ci.org/krmbzds/turkish_id.svg?branch=master)](https://travis-ci.org/krmbzds/turkish_id) [![Gem](https://img.shields.io/gem/v/turkish_id.svg)](https://github.com/krmbzds/turkish_id) [![Dependencies](https://img.shields.io/badge/dependencies-none-brightgreen.svg)](https://rubygems.org/gems/turkish_id) [![Gem](https://img.shields.io/gem/dt/turkish_id.svg)](https://rubygems.org/gems/turkish_id) [![Code Climate](https://codeclimate.com/github/krmbzds/turkish_id/badges/gpa.svg)](https://codeclimate.com/github/krmbzds/turkish_id) [![Test Coverage](https://codeclimate.com/github/krmbzds/turkish_id/badges/coverage.svg)](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 ```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:
@@ -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
- 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'`.
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](https://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 it ( http://github.com/krmbzds/turkish_id/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
- Bug reports and pull requests are welcome on GitHub at https://github.com/krmbzds/turkish_id.
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 © 2015 [Kerem Bozdaş](http://kerembozdas.com/)
129
+ Copyright © 2019 [Kerem Bozdas][Personal Webpage]
130
+
131
+ This gem is available under the terms of the [MIT License][License].
123
132
 
124
- This gem is available under the terms of the [MIT License](https://github.com/krmbzds/turkish_id/blob/master/LICENSE.txt).
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
@@ -1,6 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
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,14 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "turkish_id"
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
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
10
+ require 'irb'
14
11
  IRB.start
@@ -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,4 +1,6 @@
1
- require "turkish_id/version"
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 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 = "0.5.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: 0.5.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: 2018-07-26 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,9 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.7.6
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: []