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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 138804708933184e1ad20325ad662f9fb26a6b6841f7ebbdc844319ab6f41245
4
- data.tar.gz: 591d61b99e22b9ecc372fb0924686bbeb13a108da813cb14d730cdf22c008a8b
3
+ metadata.gz: 4369f6bf917fbd32056fcb9084fd6640a083f6cea7449d0212e3d87c5830f35e
4
+ data.tar.gz: 9bd602649636f06c50ca11a22930f7621a414285ab1a447f5927a6113946b9dd
5
5
  SHA512:
6
- metadata.gz: 026a849d7d4c4d8a605a1eb36a754ca09c249a6930930c67d1e5d4e695b3a89f2df3fe5eeed255423e1d7f0bc0126309b6513d064fbe683d1a96c3b4bcd3855c
7
- data.tar.gz: c3153324521c9baa73603483925c5f43d5dbd7464992cadd7995d0b3c5294da1c57363b6c675884f0aef125d03231f154ba9593542a4ed351b8f5ebfe2a545a9
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
- * Rails model 內驗證 (Rails 3+/4)
10
- * Rails model 外驗證
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
- * `allow_nil` or `allow_blank`
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
- * Case sensitive, default is true
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
- [新式統一證號](http://www.registration.fcu.edu.tw/wSite/public/Attachment/f1582594331972.pdf)
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
- 1. Fork it ( https://github.com/[my-github-username]/taiwanese_id_validator/fork )
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
@@ -2,6 +2,9 @@ require 'taiwanese_id_validator/twid_mapping'
2
2
 
3
3
  module TwidValidator
4
4
  def self.valid?(twid, case_sensitive = true)
5
+ return false if !twid
6
+ return false if !twid.is_a?(String)
7
+
5
8
  twid = twid.upcase unless case_sensitive
6
9
 
7
10
  return false if twid.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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "taiwanese_id_validator"
3
- spec.version = "0.0.2"
3
+ spec.version = "0.0.3"
4
4
  spec.authors = ["Wayne Chu"]
5
5
  spec.email = ["wayne.5540@gmail.com"]
6
6
  spec.summary = "Taiwanese Id Validator."
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.2
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: 2021-12-27 00:00:00.000000000 Z
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.1.6
117
+ rubygems_version: 3.4.10
116
118
  signing_key:
117
119
  specification_version: 4
118
120
  summary: Taiwanese Id Validator.
data/CHANGELOG DELETED
@@ -1,11 +0,0 @@
1
- # Changelog
2
-
3
- ## V0.0.2
4
-
5
- - Support new International ID format PR#1
6
- - Upgrade bundler dependency, now requires version >= 2.2.33
7
-
8
-
9
- ## V0.0.1
10
-
11
- First version