ssn_validation 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/README.md +43 -0
- data/lib/ssn_validation.rb +7 -0
- data/lib/validators/social_security_number_validator.rb +4 -1
- data/lib/version.rb +1 -1
- data/test/lib/validators/social_security_number_validator_test.rb +28 -16
- metadata +5 -3
- data/ssn_validation-0.1.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cff944596627e765443786de2ce3ed67c257a348eb516ba002ade8d0adffc5cf
|
4
|
+
data.tar.gz: 636d1c1ce54b93c06a6d4d6ed3a66f09c067f856a216700df4a20ecda869f705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73e9389c9c5e3b812019084d4dd1a4523712b0684a4c85cc2d59895046d6b24eaa99fb9f43fb36881fee827ec594e36af87b0e131a7eb7ca306fdbdfdd9461b1
|
7
|
+
data.tar.gz: 66ed232ac6c6dc0c1ff3b45b43a6f8c3fa204d8880279a7daeb3d12fb29e1c4af9d7d9fa68376fc1229e04d16df2840e48b9b7956dfec1a7da35588bcd56fe6d
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ssn_validation (0.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (5.2.3)
|
10
|
+
activesupport (= 5.2.3)
|
11
|
+
activesupport (5.2.3)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
concurrent-ruby (1.1.5)
|
17
|
+
i18n (1.7.0)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
minitest (5.12.2)
|
20
|
+
rake (12.3.3)
|
21
|
+
thread_safe (0.3.6)
|
22
|
+
tzinfo (1.2.5)
|
23
|
+
thread_safe (~> 0.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
activemodel (~> 5)
|
30
|
+
rake (~> 12)
|
31
|
+
ssn_validation!
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# SsnValidation
|
2
|
+
|
3
|
+
SsnValidation is a very basic ruby gem that can validate a US Social Security Number (SSN) or ITIN. It returns a hash of error keys/messages that can be
|
4
|
+
used within ActiveRecord errors or otherwise to ensure syntactically valid SSNs.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ssn_validation'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ssn_validation
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```
|
25
|
+
❯ irb
|
26
|
+
> require 'ssn_validation'
|
27
|
+
> SsnValidation::Ssn.validate('abc')
|
28
|
+
=> {:nine_digits=>"SSN value is not 9 digits", :non_digits=>"SSN value contains non-digits"}
|
29
|
+
> SsnValidation::Ssn.validate(123006789)
|
30
|
+
=> {:zero_group=>"SSN value contains zeros in group number xxx-00-xxxx"}
|
31
|
+
> SsnValidation::Ssn.validate(nil)
|
32
|
+
=> {:nine_digits=>"SSN value is not 9 digits"}
|
33
|
+
> SsnValidation::Ssn.validate('')
|
34
|
+
=> {:nine_digits=>"SSN value is not 9 digits"}
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/johnsinco/ssn_validation
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/ssn_validation.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'ssn_validation/ssn'
|
3
|
+
|
1
4
|
module ActiveModel
|
2
5
|
module Validations
|
3
6
|
class SocialSecurityNumberValidator < EachValidator
|
4
7
|
def validate_each(record, attribute, value)
|
5
|
-
ssn_errors = Ssn.validate(value)
|
8
|
+
ssn_errors = SsnValidation::Ssn.validate(value)
|
6
9
|
return if ssn_errors.blank?
|
7
10
|
ssn_errors.values.each {|error| record.errors[attribute] << error}
|
8
11
|
end
|
data/lib/version.rb
CHANGED
@@ -1,18 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'active_model'
|
3
|
+
require 'ssn_validation'
|
4
|
+
require 'validators/social_security_number_validator'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
class SsnTestModel
|
7
|
+
include ActiveModel::Validations
|
8
|
+
attr_accessor :ssn
|
9
|
+
validates :ssn, social_security_number: true
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
class SocialSecurityNumberValidatorTest < Minitest::Test
|
13
|
+
describe 'it uses the ssn validation rules' do
|
14
|
+
it 'validates' do
|
15
|
+
subject = SsnTestModel.new
|
16
|
+
subject.ssn = '123454321'
|
17
|
+
assert subject.valid?
|
18
|
+
assert_equal({}, subject.errors.to_h)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'can use the ascending validation rules' do
|
22
|
+
SsnValidation.config.enable_ascending = true
|
23
|
+
subject = SsnTestModel.new
|
24
|
+
subject.ssn = '123456789'
|
25
|
+
subject.valid?
|
26
|
+
assert_equal({ssn: 'SSN value contains all ASCENDING digits'}, subject.errors.to_h)
|
27
|
+
SsnValidation.config.enable_ascending = false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssn_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,13 +44,15 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- README.md
|
47
50
|
- Rakefile
|
48
51
|
- lib/ssn_validation.rb
|
49
52
|
- lib/ssn_validation/ssn.rb
|
50
53
|
- lib/ssn_validation/ssn_validation.rb
|
51
54
|
- lib/validators/social_security_number_validator.rb
|
52
55
|
- lib/version.rb
|
53
|
-
- ssn_validation-0.1.2.gem
|
54
56
|
- ssn_validation.gemspec
|
55
57
|
- test/lib/ssn_validation/ssn_test.rb
|
56
58
|
- test/lib/ssn_validation_test.rb
|
data/ssn_validation-0.1.2.gem
DELETED
Binary file
|