defra_ruby_validators 2.5.2 → 2.6.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e9394d56a860bc591e8858943843bae425845124bdca40f68f90fa864e3bbc6
|
4
|
+
data.tar.gz: 259e137a79906fb23ca984322d0e7d87dfa117cd87f4b5f87df182a69fec8cd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5336207fa6acbb53f0c36cb3759ea3d31e507de9392e2c0081bed9160bad765de799a88b6a8b4295daa80ec534f00ab158ae606e6592d624bbd8cfa48d34c69a
|
7
|
+
data.tar.gz: c81e615d1b0337ff9e21380f80a91d50670ec5b95c950a35e346feda88822e34f0e9660f81b7e75d200b6b0fc83cff2d05af79e383b78123c7edab9fb46563e8
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uk_postcode"
|
4
|
+
|
5
|
+
module DefraRuby
|
6
|
+
module Validators
|
7
|
+
class PostcodeValidator < BaseValidator
|
8
|
+
include CanValidatePresence
|
9
|
+
|
10
|
+
def validate_each(record, attribute, value)
|
11
|
+
return false unless value_is_present?(record, attribute, value)
|
12
|
+
|
13
|
+
valid_format?(record, attribute, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def valid_format?(record, attribute, value)
|
19
|
+
parsed_value = UKPostcode.parse(value)
|
20
|
+
return true if (normalise(parsed_value) == normalise(value)) && parsed_value.full_valid?
|
21
|
+
|
22
|
+
add_validation_error(record, attribute, :invalid_format)
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def normalise(postcode)
|
27
|
+
postcode.to_s.downcase.gsub(/\s+/, "")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -20,6 +20,7 @@ require_relative "validators/location_validator"
|
|
20
20
|
require_relative "validators/phone_number_validator"
|
21
21
|
require_relative "validators/mobile_phone_number_validator"
|
22
22
|
require_relative "validators/position_validator"
|
23
|
+
require_relative "validators/postcode_validator"
|
23
24
|
require_relative "validators/token_validator"
|
24
25
|
require_relative "validators/true_false_validator"
|
25
26
|
require_relative "validators/past_date_validator"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defra_ruby_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Defra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: uk_postcode
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: validates_email_format_of
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +143,7 @@ files:
|
|
129
143
|
- config/locales/defra_ruby/validators/past_date_validator/en.yml
|
130
144
|
- config/locales/defra_ruby/validators/phone_number_validator/en.yml
|
131
145
|
- config/locales/defra_ruby/validators/position_validator/en.yml
|
146
|
+
- config/locales/defra_ruby/validators/postcode_validator/en.yml
|
132
147
|
- config/locales/defra_ruby/validators/token_validator/en.yml
|
133
148
|
- config/locales/defra_ruby/validators/true_false_validator/en.yml
|
134
149
|
- lib/defra_ruby/validators.rb
|
@@ -149,6 +164,7 @@ files:
|
|
149
164
|
- lib/defra_ruby/validators/past_date_validator.rb
|
150
165
|
- lib/defra_ruby/validators/phone_number_validator.rb
|
151
166
|
- lib/defra_ruby/validators/position_validator.rb
|
167
|
+
- lib/defra_ruby/validators/postcode_validator.rb
|
152
168
|
- lib/defra_ruby/validators/token_validator.rb
|
153
169
|
- lib/defra_ruby/validators/true_false_validator.rb
|
154
170
|
- lib/defra_ruby/validators/version.rb
|