kangal 1.0.0 → 1.1.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/CHANGELOG.md +47 -20
- data/README.md +50 -6
- data/config/locales/en.yml +5 -1
- data/config/locales/fr.yml +14 -0
- data/config/locales/tr.yml +5 -1
- data/lib/kangal.rb +2 -0
- data/lib/kangal/identity_number.rb +54 -0
- data/lib/kangal/tax_number.rb +45 -0
- data/lib/kangal/version.rb +1 -1
- data/spec/identity_number_spec.rb +24 -0
- data/spec/tax_number_spec.rb +24 -0
- metadata +8 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9c6e5ebc471b05747256ef6bf399bc81793402c
|
|
4
|
+
data.tar.gz: 765f8597f5d52b33fac03ba7b9ac8bc61ed6e50c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12b1ec5cf986cf59062ed32380d5305e3ed578839ce2052cecd7701310c8bd5bb15152b75aba0b7556c2ff53644a03c250bdfd99a22817c22f363176b981916d
|
|
7
|
+
data.tar.gz: c9d637cf15a46316fc8944ba2f5e1d7892209ab2a4c51e77d3f38b00d434d522c9aaac4b4ab2f1dd940549ee564a20c5e08693ca4019b362b7cb555f04cd797f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,48 @@
|
|
|
1
|
-
#### 1.0.0
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* [
|
|
10
|
-
* [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* [
|
|
20
|
-
* [
|
|
21
|
-
* [
|
|
2
|
+
#### [Current]
|
|
3
|
+
* [3b644b2](../../commit/3b644b2) - __(Onur Özgür ÖZKAN)__ typo fixed.
|
|
4
|
+
* [a7c1f82](../../commit/a7c1f82) - __(hamitturkukaya)__ [#11](../../issues/11) Turkish Government Tax Number for company validation implemented
|
|
5
|
+
|
|
6
|
+
- Changelog and Readme Updated
|
|
7
|
+
|
|
8
|
+
* [b34a9df](../../commit/b34a9df) - __(hamitturkukaya)__ [#11](../../issues/11) Turkish Government Tax Number for company validation implemented
|
|
9
|
+
* [22f50ed](../../commit/22f50ed) - __(hamitturkukaya)__ [#12](../../issues/12) Turkish Government Identity Number validation
|
|
10
|
+
|
|
11
|
+
- Readme.md an Changelog.md updated
|
|
12
|
+
|
|
13
|
+
* [a194920](../../commit/a194920) - __(hamitturkukaya)__ [#12](../../issues/12) Turkish Government Identity Number validation
|
|
14
|
+
|
|
15
|
+
- New validation method added
|
|
16
|
+
- Rspec fails fixed
|
|
17
|
+
|
|
18
|
+
* [4e89b77](../../commit/4e89b77) - __(hamitturkukaya)__ [#12](../../issues/12) Turkish Government Identity Number checked
|
|
19
|
+
* [afc8352](../../commit/afc8352) - __(Muhammet DİLEK)__ readme updated
|
|
20
|
+
* [dc23c13](../../commit/dc23c13) - __(Muhammet DİLEK)__ readme updated
|
|
21
|
+
* [0be7a3c](../../commit/0be7a3c) - __(Muhammet DİLEK)__ typo fixed
|
|
22
|
+
* [aacb1e0](../../commit/aacb1e0) - __(Onur Özgür ÖZKAN)__ Add fr.yml
|
|
23
|
+
* [c776763](../../commit/c776763) - __(Onur Ozgur OZKAN)__ bump version 1.0.0
|
|
24
|
+
* [2b6753e](../../commit/2b6753e) - __(Muhammet DİLEK)__ [#3](../../issues/3) subdomain validator added
|
|
25
|
+
|
|
26
|
+
#### 0.1.2
|
|
27
|
+
* [965d580](../../commit/965d580) - __(Onur Ozgur OZKAN)__ bump version 0.1.2
|
|
28
|
+
* [eacf477](../../commit/eacf477) - __(Onur Ozgur OZKAN)__ [#8](../../issues/8) rename gem cerberus to kangal
|
|
29
|
+
* [ca1bc8f](../../commit/ca1bc8f) - __(Onur Ozgur OZKAN)__ bump version
|
|
30
|
+
* [d7a0d8e](../../commit/d7a0d8e) - __(Onur Ozgur OZKAN)__ add summary and description to gemspec file.
|
|
31
|
+
|
|
32
|
+
#### 1.0.0
|
|
33
|
+
* [41e3589](../../commit/41e3589) - __(Onur Ozgur OZKAN)__ add CHANGELOG.md
|
|
34
|
+
* [bca3a4c](../../commit/bca3a4c) - __(Onur Ozgur OZKAN)__ add CHANGELOG.md
|
|
35
|
+
* [8a5dd69](../../commit/8a5dd69) - __(Onur Ozgur OZKAN)__ [#7](../../issues/7) add travis-ci flag to README.md
|
|
36
|
+
* [5a48bab](../../commit/5a48bab) - __(Onur Ozgur OZKAN)__ [#2](../../issues/2) fixed email format for spec
|
|
37
|
+
* [382d3d1](../../commit/382d3d1) - __(Onur Ozgur OZKAN)__ [#7](../../issues/7) add travis-ci service
|
|
38
|
+
* [85ad341](../../commit/85ad341) - __(Onur Ozgur OZKAN)__ Improve README.md
|
|
39
|
+
* [4a986b9](../../commit/4a986b9) - __(Onur Ozgur OZKAN)__ [#5](../../issues/5) add locale system and files
|
|
40
|
+
* [80f0aea](../../commit/80f0aea) - __(Onur Ozgur OZKAN)__ [#2](../../issues/2) add email validation
|
|
41
|
+
* [189bbba](../../commit/189bbba) - __(Onur Ozgur OZKAN)__ [#2](../../issues/2) add spec for email
|
|
42
|
+
* [42b68b5](../../commit/42b68b5) - __(Onur Ozgur OZKAN)__ [#4](../../issues/4) setup rspec and rake
|
|
43
|
+
* [34cc03a](../../commit/34cc03a) - __(Onur Ozgur OZKAN)__ [#4](../../issues/4) set rspec and rake
|
|
44
|
+
* [3d0b486](../../commit/3d0b486) - __(Onur Ozgur OZKAN)__ [#1](../../issues/1) fix license.txt
|
|
45
|
+
* [cd9ed2e](../../commit/cd9ed2e) - __(Onur Ozgur OZKAN)__ [#1](../../issues/1) convert double quotes to single quotes
|
|
46
|
+
* [c9896cb](../../commit/c9896cb) - __(Onur Ozgur OZKAN)__ [#1](../../issues/1) setup Code Climate and Gemnasium
|
|
47
|
+
* [8ef9ff8](../../commit/8ef9ff8) - __(Onur Ozgur OZKAN)__ [#1](../../issues/1) setup gem
|
|
48
|
+
* [29e3e1e](../../commit/29e3e1e) - __(Onur Ozgur OZKAN)__ [#1](../../issues/1) setup gem
|
data/README.md
CHANGED
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
[](https://gemnasium.com/kebab-project/kangal)
|
|
5
5
|
[](https://travis-ci.org/kebab-project/kangal)
|
|
6
6
|
|
|
7
|
-
NOTE: Don't use this gem until v1.0.0
|
|
8
|
-
|
|
9
|
-
**Kangal**
|
|
10
7
|
|
|
11
8
|
## Requirements
|
|
12
9
|
|
|
@@ -62,7 +59,7 @@ end
|
|
|
62
59
|
|
|
63
60
|
|
|
64
61
|
p = User.new
|
|
65
|
-
p.subdomain = "
|
|
62
|
+
p.subdomain = "www"
|
|
66
63
|
p.valid? # => false
|
|
67
64
|
|
|
68
65
|
p.subdomain = "https"
|
|
@@ -77,12 +74,59 @@ p.valid? # => false
|
|
|
77
74
|
p.subdomain = "foo"
|
|
78
75
|
p.valid? # => false
|
|
79
76
|
|
|
80
|
-
p.
|
|
77
|
+
p.subdomain = "lab2023"
|
|
81
78
|
p.valid? # => true
|
|
82
79
|
```
|
|
83
80
|
|
|
84
81
|
**Default reserved names:** www, ftp, mail, pop, smtp, admin, ssl, sftp, http, https
|
|
85
82
|
|
|
83
|
+
## Turkish Government Identity Number Validator
|
|
84
|
+
```ruby
|
|
85
|
+
require 'kangal'
|
|
86
|
+
class User
|
|
87
|
+
include ActiveModel::Validations
|
|
88
|
+
attr_accessor :identity
|
|
89
|
+
|
|
90
|
+
# Identity Number validator
|
|
91
|
+
validates :email, presence: :true, identity_number: :true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
p = User.new
|
|
95
|
+
p.identity = "44234234"
|
|
96
|
+
p.valid? # => false
|
|
97
|
+
|
|
98
|
+
p = User.new
|
|
99
|
+
p.identity = "02343214582"
|
|
100
|
+
p.valid? # => false
|
|
101
|
+
|
|
102
|
+
p = User.new
|
|
103
|
+
p.identity = "83317527040" # (this isn't a real identity number)
|
|
104
|
+
p.valid? # => true
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Turkish Government Tax Number Validator
|
|
108
|
+
```ruby
|
|
109
|
+
require 'kangal'
|
|
110
|
+
class User
|
|
111
|
+
include ActiveModel::Validations
|
|
112
|
+
attr_accessor :tax_number
|
|
113
|
+
|
|
114
|
+
# Identity Number validator
|
|
115
|
+
validates :tax_number, presence: :true, tax_number: :true
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
p = User.new
|
|
119
|
+
p.tax_number = "44234234"
|
|
120
|
+
p.valid? # => false
|
|
121
|
+
|
|
122
|
+
p = User.new
|
|
123
|
+
p.tax_number = "02343214582"
|
|
124
|
+
p.valid? # => false
|
|
125
|
+
|
|
126
|
+
p = User.new
|
|
127
|
+
p.tax_number = "6120069217" # (this isn't a real tax number)
|
|
128
|
+
p.valid? # => true
|
|
129
|
+
```
|
|
86
130
|
|
|
87
131
|
## Bugs and Feedback
|
|
88
132
|
|
|
@@ -110,4 +154,4 @@ Once you've made your great commits:
|
|
|
110
154
|
|
|
111
155
|
## License
|
|
112
156
|
|
|
113
|
-
Copyright 2012 lab2023 – internet technologies
|
|
157
|
+
Copyright 2012 lab2023 – internet technologies
|
data/config/locales/en.yml
CHANGED
|
@@ -7,4 +7,8 @@ en:
|
|
|
7
7
|
reserved: 'cannot be a reserved name'
|
|
8
8
|
character: 'must have between 3 and 63 letters'
|
|
9
9
|
hyphen: 'cannot start or end with a hyphen'
|
|
10
|
-
alphanumeric: 'must be alphanumeric; A-Z, 0-9 or hyphen'
|
|
10
|
+
alphanumeric: 'must be alphanumeric; A-Z, 0-9 or hyphen'
|
|
11
|
+
identity_number:
|
|
12
|
+
invalid: 'is invalid.'
|
|
13
|
+
tax_number:
|
|
14
|
+
invalid: 'is invalid.'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
en:
|
|
2
|
+
kangal:
|
|
3
|
+
validations:
|
|
4
|
+
email:
|
|
5
|
+
invalid: 'est invalide'
|
|
6
|
+
subdomain:
|
|
7
|
+
reserved: 'ce nom ne peut pas être réservé'
|
|
8
|
+
character: 'il faut que ce soit entre 3 et 63 lettres'
|
|
9
|
+
hyphen: 'il peut pas commencer ou finir avec un trait'
|
|
10
|
+
alphanumeric: 'il faut être alphanumérique; A-Z, 0-9 ou trait'
|
|
11
|
+
identity_number:
|
|
12
|
+
invalid: 'est invalide.'
|
|
13
|
+
tax_number:
|
|
14
|
+
invalid: 'est invalide.'
|
data/config/locales/tr.yml
CHANGED
|
@@ -7,4 +7,8 @@ tr:
|
|
|
7
7
|
reserved: 'bu isim alınamaz'
|
|
8
8
|
character: '3 ile 63 karakter arasında olmalıdır'
|
|
9
9
|
hyphen: 'tire ile başalayamaz veya bitemez'
|
|
10
|
-
alphanumeric: 'alfanümerik olmalıdır; A-Z, 0-9 veya tire'
|
|
10
|
+
alphanumeric: 'alfanümerik olmalıdır; A-Z, 0-9 veya tire'
|
|
11
|
+
identity_number:
|
|
12
|
+
invalid: 'geçersizdir.'
|
|
13
|
+
tax_number:
|
|
14
|
+
invalid: 'geçersizdir.'
|
data/lib/kangal.rb
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'active_model'
|
|
2
|
+
require 'active_model/validations'
|
|
3
|
+
|
|
4
|
+
class IdentityNumberValidator < ActiveModel::EachValidator
|
|
5
|
+
|
|
6
|
+
def validate_each(record, attribute, value)
|
|
7
|
+
valid = true
|
|
8
|
+
val = value.to_s
|
|
9
|
+
if val.size == 11 && val[0].to_i != 0
|
|
10
|
+
valid = check_tenth_character(val)
|
|
11
|
+
valid = check_eleventh_character(val)
|
|
12
|
+
valid = double_check_eleventh_character(val)
|
|
13
|
+
else
|
|
14
|
+
valid = false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.identity_number')) unless valid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def check_eleventh_character(val)
|
|
23
|
+
sum = 0
|
|
24
|
+
(0..9).each do |counter|
|
|
25
|
+
sum += val[counter].to_i
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
val[10].to_i == sum % 10
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def check_tenth_character(val)
|
|
32
|
+
odd_sum = 0
|
|
33
|
+
even_sum = 0
|
|
34
|
+
(0..8).each do |counter|
|
|
35
|
+
if counter.even?
|
|
36
|
+
odd_sum += val[counter].to_i
|
|
37
|
+
else
|
|
38
|
+
even_sum += val[counter].to_i
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
val[9].to_i == ((odd_sum*7 + even_sum*9)%10)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def double_check_eleventh_character(val)
|
|
45
|
+
sum = 0
|
|
46
|
+
(0..8).each do |counter|
|
|
47
|
+
if counter.even?
|
|
48
|
+
sum += val[counter].to_i
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
val[10].to_i == ((sum*8)%10)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'active_model'
|
|
2
|
+
require 'active_model/validations'
|
|
3
|
+
|
|
4
|
+
class TaxNumberValidator < ActiveModel::EachValidator
|
|
5
|
+
|
|
6
|
+
def validate_each(record, attribute, value)
|
|
7
|
+
valid = true
|
|
8
|
+
val = value.to_s
|
|
9
|
+
if val.size == 10
|
|
10
|
+
val1 = Array.new
|
|
11
|
+
val2 = Array.new
|
|
12
|
+
last_digit = val[9].to_i
|
|
13
|
+
|
|
14
|
+
(0..8).each do |index|
|
|
15
|
+
val1 << ((val[index].to_i + (9 - index)) % 10).to_i
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
(0..8).each do |index|
|
|
19
|
+
val2 << ((val1[index].to_i * (2 ** (9 - index))) % 9).to_i
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
(0..8).each do |index|
|
|
23
|
+
val2[index] = 9 if (val1[index] != 0 && val2[index] == 0)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
sum = 0
|
|
27
|
+
|
|
28
|
+
(0..8).each do |index|
|
|
29
|
+
sum += val2[index]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if (sum % 10) == 0
|
|
33
|
+
sum = 0
|
|
34
|
+
else
|
|
35
|
+
sum = 10 - (sum % 10)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
valid = (sum == last_digit)
|
|
39
|
+
|
|
40
|
+
else
|
|
41
|
+
valid = false
|
|
42
|
+
end
|
|
43
|
+
record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.tax_number')) unless valid
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/kangal/version.rb
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Profile < SpecModel
|
|
4
|
+
validates :identity, identity_number: true
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe 'Identity number format' do
|
|
8
|
+
|
|
9
|
+
let(:invalid_identity_numbers) do
|
|
10
|
+
%w(1 3 434542345678)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:valid_identity_numbers) do
|
|
14
|
+
%w(21432692144 55679901158 83317527040)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should be invalid' do
|
|
18
|
+
invalid_identity_numbers.each { |identity| Profile.new(identity: identity).valid?.should be_false }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'should be valid' do
|
|
22
|
+
valid_identity_numbers.each { |identity| Profile.new(identity: identity).valid?.should be_true }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class CompanyDetail < SpecModel
|
|
4
|
+
validates :tax, tax_number: true
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe 'tax number format' do
|
|
8
|
+
|
|
9
|
+
let(:invalid_tax_numbers) do
|
|
10
|
+
%w(1 3 434542345678 43454234567)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:valid_tax_numbers) do
|
|
14
|
+
%w(2640020928 6120069217)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should be invalid' do
|
|
18
|
+
invalid_tax_numbers.each { |tax| CompanyDetail.new(tax: tax).valid?.should be_false }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'should be valid' do
|
|
22
|
+
valid_tax_numbers.each { |tax| CompanyDetail.new(tax: tax).valid?.should be_true }
|
|
23
|
+
end
|
|
24
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kangal
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- lab2023
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -97,15 +97,20 @@ files:
|
|
|
97
97
|
- README.md
|
|
98
98
|
- Rakefile
|
|
99
99
|
- config/locales/en.yml
|
|
100
|
+
- config/locales/fr.yml
|
|
100
101
|
- config/locales/tr.yml
|
|
101
102
|
- kangal.gemspec
|
|
102
103
|
- lib/kangal.rb
|
|
103
104
|
- lib/kangal/email.rb
|
|
105
|
+
- lib/kangal/identity_number.rb
|
|
104
106
|
- lib/kangal/subdomain.rb
|
|
107
|
+
- lib/kangal/tax_number.rb
|
|
105
108
|
- lib/kangal/version.rb
|
|
106
109
|
- spec/email_spec.rb
|
|
110
|
+
- spec/identity_number_spec.rb
|
|
107
111
|
- spec/spec_helper.rb
|
|
108
112
|
- spec/subdomain_spec.rb
|
|
113
|
+
- spec/tax_number_spec.rb
|
|
109
114
|
homepage: https://github.com/kebab-project/kangal
|
|
110
115
|
licenses:
|
|
111
116
|
- MIT
|
|
@@ -126,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
126
131
|
version: '0'
|
|
127
132
|
requirements: []
|
|
128
133
|
rubyforge_project:
|
|
129
|
-
rubygems_version: 2.0.
|
|
134
|
+
rubygems_version: 2.0.6
|
|
130
135
|
signing_key:
|
|
131
136
|
specification_version: 4
|
|
132
137
|
summary: Kangal brings you a nice set of custom validators for Rails 4.
|