turkish_id 1.1.0 → 1.4.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: eb43dd80bbbae38c2fcd5daa63b9eadfebe7ba1bd5032a03e59f9d7677377468
4
- data.tar.gz: 5b7766508c37022ec4a122c9e51a15634cd39addfdfb561e9b932082138fcb5c
3
+ metadata.gz: 4dbab23fd1a1c8ee8c67c3630a171a135bed41bce82708dc6c03c42b61651bf3
4
+ data.tar.gz: '0385cf9eb915caf2a0f8c41cb3663e7bdb2c9b50d17b8915f6fc2e1416eab8f8'
5
5
  SHA512:
6
- metadata.gz: 9ebe0fcdac09682b534d5096373b637c140cfe727a4c0b7041f0c892b40023164a10a35dffb792b6fd5eda6d4ca19041b5360ebcfe8d9f0371b9f92777600a3f
7
- data.tar.gz: b495c90ebb3bd35222c48ba64bb228b3341bb62c778fb24c498bf063ac14008cc2e07180e61591fe5d0eb26461a50a46e2968d31c60ae1298e0d83bb6792d80a
6
+ metadata.gz: 39f88acd307c6a3ac8d5c446cad44ed78a5fb7f998d8fdd4223c5550705880d67d617ed106f1465de98fb9c3c92415e72901b5ce8582fe3a04d80502f8c1402e
7
+ data.tar.gz: 6fa037e2073337069638a364f2a8277f48d50630a0bd80f46a43a5ef49bd674b5226dcfa941dd59d02c7c43466a8b6403be4288df33ad3403fbd748b04f6497a
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "03:00"
8
+ open-pull-requests-limit: 10
@@ -0,0 +1,24 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Publish Packages
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ bundler-cache: true
19
+
20
+ - name: Publish to RubyGems
21
+ uses: dawidd6/action-publish-gem@v1
22
+ with:
23
+ api_key: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
24
+
@@ -0,0 +1,53 @@
1
+ name: Test
2
+
3
+ on:
4
+ pull_request:
5
+
6
+ push:
7
+ branches: [ develop, master ]
8
+
9
+ env:
10
+ GIT_COMMIT_SHA: ${{ github.sha }}
11
+ GIT_BRANCH: ${{ github.ref }}
12
+ COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
13
+
14
+ jobs:
15
+
16
+ lint:
17
+ runs-on: ubuntu-latest
18
+ name: lint ${{ matrix.ruby }}
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ ruby: [ '2.6.9', '2.7.5', '3.0.3', '3.1.1' ]
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ bundler-cache: true
30
+
31
+ - name: StandardRB
32
+ continue-on-error: ${{ matrix.experimental }}
33
+ run: bundle exec standardrb --parallel --format progress
34
+
35
+ test:
36
+ needs: [ lint ]
37
+ runs-on: ubuntu-latest
38
+ name: test ${{ matrix.ruby }}
39
+ strategy:
40
+ fail-fast: false
41
+ matrix:
42
+ ruby: [ '2.6.9', '2.7.5', '3.0.3', '3.1.1' ]
43
+
44
+ steps:
45
+ - uses: actions/checkout@v2
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{ matrix.ruby }}
49
+ bundler-cache: true
50
+
51
+ - name: Test
52
+ continue-on-error: ${{ matrix.experimental }}
53
+ run: bundle exec rake
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.1
data/Gemfile CHANGED
@@ -1,11 +1,8 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
- # Specify your gem's dependencies in turkish_id.gemspec
4
- gemspec
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
6
 
6
- group :test do
7
- gem 'rake'
8
- gem 'bundler'
9
- gem 'rspec'
10
- gem 'simplecov'
11
- end
7
+ # Specify your gem's dependencies in viabtc.gemspec
8
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Kerem Bozdas
3
+ Copyright (c) 2015-2022 Kerem Bozdas
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Turkish ID 🔖
2
2
 
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)
3
+ [![Status](https://img.shields.io/github/workflow/status/krmbzds/turkish_id/Test/master)](https://github.com/krmbzds/turkish_id/actions/workflows/test.yml)
4
+ [![Coverage](https://img.shields.io/coveralls/github/krmbzds/turkish_id)](https://coveralls.io/github/krmbzds/turkish_id)
5
+ [![Downloads](https://img.shields.io/gem/dt/turkish_id.svg)](https://rubygems.org/gems/turkish_id)
6
+ [![Dependencies](https://img.shields.io/badge/dependencies-none-brightgreen.svg)](https://rubygems.org/gems/turkish_id)
7
+ [![Maintainability](https://img.shields.io/codeclimate/maintainability/krmbzds/turkish_id)](https://codeclimate.com/github/krmbzds/turkish_id)
8
+ [![Version](https://img.shields.io/gem/v/turkish_id.svg)](https://github.com/krmbzds/turkish_id)
9
+ [![Docs](https://img.shields.io/badge/rubydoc-info-blue.svg)](https://www.rubydoc.info/gems/turkish_id)
4
10
 
5
11
  This gem provides methods to validate Turkish Identification Numbers.
6
12
 
@@ -30,16 +36,19 @@ Create a new instance:
30
36
  identity_number = TurkishId.new(10000000146)
31
37
  ```
32
38
 
33
- Use ```is_valid?``` method to check validity:
39
+ Use ```valid?``` method to check validity:
34
40
 
35
41
  ```rb
36
- identity_number.is_valid? #=> true
42
+ identity_number.valid? #=> true
37
43
  ```
38
44
 
39
45
  Or use the command line executable:
40
46
 
41
47
  ```sh
42
- $ turkish_id 10000000078 #=> Your identification number is valid.
48
+ $ turkish_id 10000000078 #=> true
49
+ $ echo $? #=> 0
50
+ $ turkish_id 10000000079 #=> false
51
+ $ echo $? #=> 1
43
52
  ```
44
53
 
45
54
  ### Generating Relatives
@@ -98,9 +107,10 @@ Remember that a valid identification number does not imply the existence of an I
98
107
 
99
108
  This gem is used in production and tested against the following Ruby versions:
100
109
 
101
- - ✅ `2.6.4` (stable)
102
- - ✅ `2.5.6` (stable)
103
- - `2.4.7` (security maintenance)
110
+ - ✅ `3.1.1` (stable)
111
+ - ✅ `3.0.3` (stable)
112
+ - `2.7.5` (stable)
113
+ - ⏳ `2.6.9` (security maintenance)
104
114
 
105
115
  ## Development
106
116
 
@@ -126,7 +136,7 @@ Yes.
126
136
 
127
137
  ## License
128
138
 
129
- Copyright © 2019 [Kerem Bozdas][Personal Webpage]
139
+ Copyright © 2015-2022 [Kerem Bozdas][Personal Webpage]
130
140
 
131
141
  This gem is available under the terms of the [MIT License][License].
132
142
 
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ # frozen_string_literal: true
3
2
 
4
- RSpec::Core::RakeTask.new(:spec)
5
- task :default => :spec
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
6
5
 
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
data/bin/console CHANGED
@@ -1,10 +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
- require 'irb'
10
+ require "irb"
10
11
  IRB.start
data/bin/setup CHANGED
File without changes
data/bin/turkish_id CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
5
5
  $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
6
 
7
- require 'turkish_id'
7
+ require "turkish_id"
8
8
 
9
9
  @help = '
10
10
  Usage
@@ -16,21 +16,10 @@ require 'turkish_id'
16
16
 
17
17
  '
18
18
 
19
- def parse_input
20
- ARGV[0] ? validate_id(ARGV[0]) : print_help
19
+ if ARGV[0]
20
+ result = TurkishId.new(ARGV[0]).valid?
21
+ $stdout.puts result
22
+ exit result ? 0 : 1
23
+ else
24
+ $stdout.puts @help
21
25
  end
22
-
23
- def validate_id(id_number)
24
- identity_number = TurkishId.new(id_number)
25
- print_result(identity_number.is_valid?)
26
- end
27
-
28
- def print_result(result)
29
- STDOUT.puts "Your identification number is #{ result ? 'valid' : 'invalid' }."
30
- end
31
-
32
- def print_help
33
- STDOUT.puts @help
34
- end
35
-
36
- parse_input
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class TurkishId
2
- VERSION = '1.1.0'
4
+ VERSION = "1.4.0"
3
5
  end
data/lib/turkish_id.rb CHANGED
@@ -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
@@ -46,8 +42,8 @@ class TurkishId
46
42
  end
47
43
 
48
44
  def next_relative(id_array, direction)
49
- tree = { up: 1, down: -1 }
50
- get_core(id_array) + 29999 * tree[direction]
45
+ tree = {up: 1, down: -1}
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
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)
data/turkish_id.gemspec CHANGED
@@ -1,21 +1,28 @@
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
- require 'turkish_id/version'
5
+ require "turkish_id/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = 'turkish_id'
8
- spec.version = TurkishId::VERSION
9
- spec.authors = ['Kerem Bozdas']
10
- spec.email = ['krmbzds.github@gmail.com']
8
+ spec.name = "turkish_id"
9
+ spec.version = TurkishId::VERSION
10
+ spec.authors = ["Kerem Bozdas"]
11
+ spec.email = ["krmbzds.github@gmail.com"]
12
+
13
+ spec.summary = "Validate Turkish Identification Numbers and More!"
14
+ spec.description = "Validate Turkish Identification Numbers and More!"
15
+ spec.homepage = "https://github.com/krmbzds/turkish_id"
16
+ spec.license = "MIT"
11
17
 
12
- spec.summary = 'Validate Turkish Identification Numbers and More!'
13
- spec.description = 'Validate Turkish Identification Numbers and More!'
14
- spec.homepage = 'https://github.com/krmbzds/turkish_id'
15
- spec.license = 'MIT'
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "bin"
20
+ spec.executables = ["turkish_id"]
21
+ spec.require_paths = ["lib", "lib/turkish_id"]
16
22
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'bin'
19
- spec.executables = ['turkish_id']
20
- spec.require_paths = ['lib', 'lib/turkish_id']
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "standard"
27
+ spec.add_development_dependency "coveralls_reborn"
21
28
  end
metadata CHANGED
@@ -1,15 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.4.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: 2019-09-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls_reborn
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
13
83
  description: Validate Turkish Identification Numbers and More!
14
84
  email:
15
85
  - krmbzds.github@gmail.com
@@ -18,11 +88,12 @@ executables:
18
88
  extensions: []
19
89
  extra_rdoc_files: []
20
90
  files:
91
+ - ".github/dependabot.yml"
92
+ - ".github/workflows/publish.yml"
93
+ - ".github/workflows/test.yml"
21
94
  - ".gitignore"
22
95
  - ".rspec"
23
- - ".ruby-gemset"
24
- - ".ruby-version"
25
- - ".travis.yml"
96
+ - ".tool-versions"
26
97
  - Gemfile
27
98
  - LICENSE.txt
28
99
  - README.md
@@ -53,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
124
  - !ruby/object:Gem::Version
54
125
  version: '0'
55
126
  requirements: []
56
- rubygems_version: 3.0.6
127
+ rubygems_version: 3.3.7
57
128
  signing_key:
58
129
  specification_version: 4
59
130
  summary: Validate Turkish Identification Numbers and More!
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- turkish_id
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.6.4
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6.4
4
- - 2.5.6
5
- - 2.4.7
6
- before_install:
7
- - 'gem update --system'
8
- - 'gem --version'
9
- - 'gem install bundler'
10
- env:
11
- global:
12
- - CC_TEST_REPORTER_ID=92655ba2c8b47200f80e996afb80c410b9491514845d414d7517108ad35a5178
13
- before_script:
14
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
- - chmod +x ./cc-test-reporter
16
- - ./cc-test-reporter before-build
17
- script:
18
- - bundle exec rspec
19
- after_script:
20
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT