taiwanese_id_validator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/DEVELOPMENT.md +37 -0
- data/README.md +9 -17
- data/lib/international_id_validator/itid_validator.rb +3 -0
- data/lib/taiwanese_id_validator/twid_validator.rb +3 -0
- data/spec/international_id_validator/itid_validator_spec.rb +40 -0
- data/spec/taiwanese_id_validator/twid_validator_spec.rb +8 -0
- data/taiwanese_id_validator.gemspec +1 -1
- metadata +6 -4
- data/CHANGELOG +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4369f6bf917fbd32056fcb9084fd6640a083f6cea7449d0212e3d87c5830f35e
|
4
|
+
data.tar.gz: 9bd602649636f06c50ca11a22930f7621a414285ab1a447f5927a6113946b9dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8350403c7f2e5d6e80d62a193aa2d5fb46d896c07b0914309c6c718e8919123496a72550b8c321cd8596bf56cb93f09dfb197cb0738ed160c4f16cf9bcee5598
|
7
|
+
data.tar.gz: 11e07f4a93b054b8c47487a8d7e1891f880f1c35be44640e707f17f9abfb2af5c0d03b2477376b43a0556ad7d4329b49fbf8bc0cfc4ee840eddd927d56484c50
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## V0.0.3
|
4
|
+
|
5
|
+
- Fix `TwidValidator.valid?(nil)` raise Error problem [PR#3](https://github.com/wayne5540/taiwanese_id_validator/pull/3)
|
6
|
+
|
7
|
+
## V0.0.2
|
8
|
+
|
9
|
+
- Support new International ID format [PR#1](https://github.com/wayne5540/taiwanese_id_validator/pull/1)
|
10
|
+
- Upgrade bundler dependency, now requires version >= 2.2.33
|
11
|
+
|
12
|
+
## V0.0.1
|
13
|
+
|
14
|
+
First version
|
data/DEVELOPMENT.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
## Get Started
|
2
|
+
|
3
|
+
1. Fork it ( https://github.com/[my-github-username]/taiwanese_id_validator/fork )
|
4
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
5
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
6
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
7
|
+
5. Create a new Pull Request
|
8
|
+
|
9
|
+
## Run Tests
|
10
|
+
|
11
|
+
`rspec`
|
12
|
+
|
13
|
+
## Build the gem
|
14
|
+
|
15
|
+
Build the gem:
|
16
|
+
|
17
|
+
```
|
18
|
+
gem build taiwanese_id_validator.gemspec
|
19
|
+
```
|
20
|
+
|
21
|
+
Install the gem, change the version name if needed
|
22
|
+
|
23
|
+
```
|
24
|
+
gem install ./taiwanese_id_validator-0.0.3.gem
|
25
|
+
```
|
26
|
+
|
27
|
+
Push to RubyGem
|
28
|
+
|
29
|
+
```
|
30
|
+
gem push ./taiwanese_id_validator-0.0.3.gem
|
31
|
+
```
|
32
|
+
|
33
|
+
More details about how to make the gem including build, install, push can be found [here](https://guides.rubygems.org/make-your-own-gem/)
|
34
|
+
|
35
|
+
## TODOs
|
36
|
+
|
37
|
+
- Support Chinese ID Validation
|
data/README.md
CHANGED
@@ -6,11 +6,10 @@
|
|
6
6
|
|
7
7
|
## Features
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
- Rails model 內驗證 (Rails 3+/4/5/6/7)
|
10
|
+
- Rails model 外驗證
|
11
|
+
- 新式統一證號驗證
|
12
|
+
- 產生符合格式的身分證字號,可選擇男女
|
14
13
|
|
15
14
|
## Installation
|
16
15
|
|
@@ -40,7 +39,7 @@ end
|
|
40
39
|
|
41
40
|
#### Options
|
42
41
|
|
43
|
-
|
42
|
+
- `allow_nil` or `allow_blank`
|
44
43
|
|
45
44
|
```ruby
|
46
45
|
class User < ActiveRecord::Base
|
@@ -48,7 +47,7 @@ class User < ActiveRecord::Base
|
|
48
47
|
end
|
49
48
|
```
|
50
49
|
|
51
|
-
|
50
|
+
- Case sensitive, default is true
|
52
51
|
|
53
52
|
```ruby
|
54
53
|
class User < ActiveRecord::Base
|
@@ -56,7 +55,6 @@ class User < ActiveRecord::Base
|
|
56
55
|
end
|
57
56
|
```
|
58
57
|
|
59
|
-
|
60
58
|
### Validation outside the model
|
61
59
|
|
62
60
|
#### 驗證身分證字號
|
@@ -101,18 +99,12 @@ ItidValidator.valid?('A800000015') #=> false
|
|
101
99
|
|
102
100
|
## Others
|
103
101
|
|
104
|
-
[身分證公式](https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%9C%8B%E6%B0%91%E8%BA%AB%E5%88%86%E8%AD%89)
|
105
|
-
[新式統一證號](
|
106
|
-
|
102
|
+
- [身分證公式](https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%9C%8B%E6%B0%91%E8%BA%AB%E5%88%86%E8%AD%89)
|
103
|
+
- [新式統一證號](https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%B1%85%E7%95%99%E8%AD%89)
|
107
104
|
|
108
105
|
## Contributing
|
109
106
|
|
110
|
-
|
111
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
113
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
114
|
-
5. Create a new Pull Request
|
115
|
-
|
107
|
+
Check [DEVELOPMENT.md](DEVELOPMENT.md)
|
116
108
|
|
117
109
|
## LICENSE
|
118
110
|
|
@@ -2,6 +2,9 @@ require 'international_id_validator/itid_mapping'
|
|
2
2
|
|
3
3
|
module ItidValidator
|
4
4
|
def self.valid?(itid, case_sensitive = true, allow_old = false)
|
5
|
+
return false if !itid
|
6
|
+
return false if !itid.is_a?(String)
|
7
|
+
|
5
8
|
itid = itid.upcase unless case_sensitive
|
6
9
|
|
7
10
|
return false if itid.length != 10
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ItidValidator do
|
4
|
+
|
5
|
+
describe "#valid?" do
|
6
|
+
context "when id not valid" do
|
7
|
+
it "returns false if id too short" do
|
8
|
+
expect( ItidValidator.valid?("A8000") ).to be false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns false if id too long" do
|
12
|
+
expect( ItidValidator.valid?("A800000014111") ).to be false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false if id calculation is wrong" do
|
16
|
+
expect( ItidValidator.valid?("A800000013") ).to be false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false if format is wrong" do
|
20
|
+
expect( ItidValidator.valid?("YAC4713412") ).to be false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false if id is nil" do
|
24
|
+
expect( ItidValidator.valid?(nil) ).to be false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns false if id is nil" do
|
28
|
+
expect( ItidValidator.valid?(1) ).to be false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when id is valid" do
|
33
|
+
let(:id) { "A800000014" }
|
34
|
+
|
35
|
+
it "returns true" do
|
36
|
+
expect( ItidValidator.valid?(id) ).to be true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -19,6 +19,14 @@ describe TwidValidator do
|
|
19
19
|
it "returns false if format is wrong" do
|
20
20
|
expect( TwidValidator.valid?("YAC4713412") ).to be false
|
21
21
|
end
|
22
|
+
|
23
|
+
it "returns false if id is nil" do
|
24
|
+
expect( TwidValidator.valid?(nil) ).to be false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns false if id is nil" do
|
28
|
+
expect( TwidValidator.valid?(1) ).to be false
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
context "when id is valid" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taiwanese_id_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wayne Chu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -75,7 +75,8 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
77
|
- ".travis.yml"
|
78
|
-
- CHANGELOG
|
78
|
+
- CHANGELOG.md
|
79
|
+
- DEVELOPMENT.md
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE.txt
|
81
82
|
- README.md
|
@@ -87,6 +88,7 @@ files:
|
|
87
88
|
- lib/taiwanese_id_validator/twid_generator.rb
|
88
89
|
- lib/taiwanese_id_validator/twid_mapping.rb
|
89
90
|
- lib/taiwanese_id_validator/twid_validator.rb
|
91
|
+
- spec/international_id_validator/itid_validator_spec.rb
|
90
92
|
- spec/international_id_validator_spec.rb
|
91
93
|
- spec/spec_helper.rb
|
92
94
|
- spec/taiwanese_id_validator/twid_generator_spec.rb
|
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
114
|
- !ruby/object:Gem::Version
|
113
115
|
version: '0'
|
114
116
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.4.10
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: Taiwanese Id Validator.
|