number_plate_validator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -7
- data/lib/number_plate_validator/active_model.rb +20 -0
- data/lib/number_plate_validator/version.rb +1 -1
- data/lib/number_plate_validator.rb +2 -0
- data/number_plate_validator.gemspec +4 -2
- metadata +35 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28c143b186ad31f5a75070038a748bb12c031fea
|
4
|
+
data.tar.gz: 3684c2428985b85bcaf6f91d798218063cac689f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52dcfe935f18eee48c9e190664c8391a9cfce94de70ce024ac20f954f105107e9b147c413897cf7090f3234dd0f1b70dbb66b84241c541a3ad367f94ac090849
|
7
|
+
data.tar.gz: 0dd935f2db1e1b59d7c7cfa05b7869cc710c4810bde5cb4470652925253ff26163c430eb2da9c7e97c3c609fc6b373e68285f71cd88546ca8ce53c146eeca225
|
data/README.md
CHANGED
@@ -19,17 +19,34 @@ Or install it yourself as:
|
|
19
19
|
$ gem install number_plate_validator
|
20
20
|
|
21
21
|
## Usage
|
22
|
+
Use standard country code to spcify the country.
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
```
|
25
|
+
##Initialize validator:
|
26
|
+
validator = NumberPlateValidator.validator("SG")
|
25
27
|
|
26
|
-
Check if it is valid:
|
27
|
-
|
28
|
-
|
28
|
+
##Check if it is valid:
|
29
|
+
validator.is_valid?("EJ81D")
|
30
|
+
#=> true
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
validator.is_valid?("EJ81E")
|
33
|
+
#=> false
|
34
|
+
```
|
35
|
+
|
36
|
+
## ActiveModel
|
37
|
+
|
38
|
+
A `NumberPlateValidator` is provided with this gem to be used with ActiveModel. You can specify the attribute with the country information with either a symbol or a Proc.
|
32
39
|
|
40
|
+
```
|
41
|
+
class Vehicle < ActiveRecord::Base
|
42
|
+
validates :plate_number, number_plate: { country: "SG" } ##country is fixed to "SG"
|
43
|
+
|
44
|
+
##or use either of the following to get the country from the attribute country_code
|
45
|
+
##validates :plate_number, number_plate: { country: :country_code }
|
46
|
+
##validates :plate_number, number_plate: { country Proc.new { |obj| obj.country_code } }
|
47
|
+
end
|
48
|
+
|
49
|
+
```
|
33
50
|
## Development
|
34
51
|
|
35
52
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
class NumberPlateValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
country = case(options[:country])
|
6
|
+
when Proc
|
7
|
+
options[:country].call(record)
|
8
|
+
when Symbol
|
9
|
+
record.send(options[:country])
|
10
|
+
else
|
11
|
+
options[:country]
|
12
|
+
end
|
13
|
+
|
14
|
+
val = ::NumberPlateValidator.validator(country)
|
15
|
+
|
16
|
+
record.errors.add attribute, (options[:message] || "is not a valid number plate") unless val.is_valid?(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require "number_plate_validator/version"
|
2
2
|
require "active_support/inflector"
|
3
|
+
require "active_model"
|
3
4
|
require "active_support/core_ext/string"
|
4
5
|
require "number_plate_validator/validator"
|
5
6
|
require "number_plate_validator/sg_validator"
|
7
|
+
require "number_plate_validator/active_model"
|
6
8
|
|
7
9
|
module NumberPlateValidator
|
8
10
|
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["zorro.ej@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{This gem validates vehicle number/license plates. }
|
13
|
-
spec.description = %q{This gem allows you to validate a license plate number from a chosen country/region.}
|
13
|
+
spec.description = %q{This gem allows you to validate a license plate number from a chosen country/region. It also provides a validator for ActiveModel. It currently only supports Singapore.}
|
14
14
|
spec.homepage = "https://github.com/ej2015/number_plate_validator.git"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -21,8 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency "activesupport", "~>
|
24
|
+
spec.add_dependency "activesupport", "~>4.2"
|
25
|
+
spec.add_dependency "activemodel", "~>4.2"
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.13"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
28
|
spec.add_development_dependency "rspec", "~> 3.7"
|
29
|
+
spec.add_development_dependency "pry", "~>0.11"
|
28
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: number_plate_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,8 +80,23 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '3.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.11'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.11'
|
69
97
|
description: This gem allows you to validate a license plate number from a chosen
|
70
|
-
country/region.
|
98
|
+
country/region. It also provides a validator for ActiveModel. It currently only
|
99
|
+
supports Singapore.
|
71
100
|
email:
|
72
101
|
- zorro.ej@gmail.com
|
73
102
|
executables: []
|
@@ -84,6 +113,7 @@ files:
|
|
84
113
|
- bin/console
|
85
114
|
- bin/setup
|
86
115
|
- lib/number_plate_validator.rb
|
116
|
+
- lib/number_plate_validator/active_model.rb
|
87
117
|
- lib/number_plate_validator/sg_validator.rb
|
88
118
|
- lib/number_plate_validator/validator.rb
|
89
119
|
- lib/number_plate_validator/version.rb
|