postcode_validation 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbe07cc9370f09af86639db17e609b5c91fb9e6a
4
- data.tar.gz: ebc2119d78ffa900494f3a4663601b5d19873820
3
+ metadata.gz: 57328fd6ac678a16c52495ac3b0d52d570b7bd60
4
+ data.tar.gz: 8dee6be4036960966659ec23af27524e437ed18d
5
5
  SHA512:
6
- metadata.gz: 6d8b1e78377725afe985594b28e855a0dcf4ab70b2328c0832dce444b88573cf7595734e7002a6e8715f1dc4698b982ef421289cb06e45d1bc18228f303c5d54
7
- data.tar.gz: 2c773ae59d59578fb0aab31259e8a9b76571153a0a8a2edcb1d2780803a8beef7cc0fb4d4d2813c3f704712cf87d93c7c0420e9e29c857cab0a25ccce91689f2
6
+ metadata.gz: ed9c52f3533f04e9e33e9e85f2b2da07a865bf5022998162a1b4cef7f79445d19c82be438449d6d2dd509f7cfdf0c2a1812be8d2f0faf72225008c285456fa2d
7
+ data.tar.gz: 2627c832bbb3c9ed1a90cd8c6c06aa6acb866591130aedc6ad5844124ecede7c76dfa77dcb362c0827b9a57dea45b6d86920b1bebead69016f1c16c59b321f07
@@ -3,13 +3,14 @@ require_relative 'format_validators/be_postcode_validator'
3
3
  require_relative 'format_validators/gb_postcode_validator'
4
4
  require_relative 'format_validators/fr_postcode_validator'
5
5
  require_relative 'format_validators/sg_postcode_validator'
6
+ require_relative 'format_validators/in_postcode_validator'
6
7
  require_relative 'format_validators/no_op_postcode_validator'
7
8
 
8
9
  module PostcodeValidation
9
10
  module UseCase
10
11
  class ValidateAddress
11
12
  class FormatValidator
12
- def for country
13
+ def for(country)
13
14
  case country
14
15
  when 'NL'
15
16
  FormatValidators::NLPostcodeValidator.new
@@ -21,6 +22,8 @@ module PostcodeValidation
21
22
  FormatValidators::FRPostcodeValidator.new
22
23
  when 'SG'
23
24
  FormatValidators::SGPostcodeValidator.new
25
+ when 'IN'
26
+ FormatValidators::INPostcodeValidator.new
24
27
  else
25
28
  FormatValidators::NoOpPostcodeValidator.new
26
29
  end
@@ -1,10 +1,13 @@
1
1
  require_relative 'regex_validator'
2
+ require_relative 'use_external_postcode_validator'
2
3
 
3
4
  module PostcodeValidation
4
5
  module UseCase
5
6
  class ValidateAddress
6
7
  module FormatValidators
7
8
  class BEPostcodeValidator < RegexValidator
9
+ include UseExternalPostcodeValidator
10
+
8
11
  REGEX = /^[1-9]{1}[0-9]{3}$/
9
12
  end
10
13
  end
@@ -1,10 +1,13 @@
1
1
  require_relative 'regex_validator'
2
+ require_relative 'use_external_postcode_validator'
2
3
 
3
4
  module PostcodeValidation
4
5
  module UseCase
5
6
  class ValidateAddress
6
7
  module FormatValidators
7
8
  class FRPostcodeValidator < RegexValidator
9
+ include UseExternalPostcodeValidator
10
+
8
11
  REGEX = /^(F-)?((2[A|B])|[0-9]{2})[0-9]{3}$/
9
12
  end
10
13
  end
@@ -1,10 +1,13 @@
1
1
  require_relative 'regex_validator'
2
+ require_relative 'use_external_postcode_validator'
2
3
 
3
4
  module PostcodeValidation
4
5
  module UseCase
5
6
  class ValidateAddress
6
7
  module FormatValidators
7
8
  class GBPostcodeValidator < RegexValidator
9
+ include UseExternalPostcodeValidator
10
+
8
11
  REGEX = /(?i)([A-Z]{1,2}[0-9]{1,2}[A-Z]?)\s*([0-9][A-Z]{2})/
9
12
  end
10
13
  end
@@ -0,0 +1,16 @@
1
+ require_relative 'regex_validator'
2
+ require_relative 'use_format_check_only'
3
+
4
+ module PostcodeValidation
5
+ module UseCase
6
+ class ValidateAddress
7
+ module FormatValidators
8
+ class INPostcodeValidator < RegexValidator
9
+ include UseFormatCheckOnly
10
+
11
+ REGEX = /^[1-9][0-9]{5}$/
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,10 +1,13 @@
1
1
  require_relative 'regex_validator'
2
+ require_relative 'use_external_postcode_validator'
2
3
 
3
4
  module PostcodeValidation
4
5
  module UseCase
5
6
  class ValidateAddress
6
7
  module FormatValidators
7
8
  class NLPostcodeValidator < RegexValidator
9
+ include UseExternalPostcodeValidator
10
+
8
11
  REGEX = /(NL-)?(\d{4})\s*([A-Za-z]{2})/
9
12
  end
10
13
  end
@@ -1,10 +1,13 @@
1
1
  require_relative 'regex_validator'
2
+ require_relative 'use_external_postcode_validator'
2
3
 
3
4
  module PostcodeValidation
4
5
  module UseCase
5
6
  class ValidateAddress
6
7
  module FormatValidators
7
8
  class NoOpPostcodeValidator < RegexValidator
9
+ include UseExternalPostcodeValidator
10
+
8
11
  REGEX = /.*/
9
12
  end
10
13
  end
@@ -1,10 +1,13 @@
1
1
  require_relative 'regex_validator'
2
+ require_relative 'use_format_check_only'
2
3
 
3
4
  module PostcodeValidation
4
5
  module UseCase
5
6
  class ValidateAddress
6
7
  module FormatValidators
7
8
  class SGPostcodeValidator < RegexValidator
9
+ include UseFormatCheckOnly
10
+
8
11
  REGEX = /^\d{6}$/
9
12
  end
10
13
  end
@@ -0,0 +1,13 @@
1
+ module PostcodeValidation
2
+ module UseCase
3
+ class ValidateAddress
4
+ module FormatValidators
5
+ module UseExternalPostcodeValidator
6
+ def format_check_only?
7
+ false
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module PostcodeValidation
2
+ module UseCase
3
+ class ValidateAddress
4
+ module FormatValidators
5
+ module UseFormatCheckOnly
6
+ def format_check_only?
7
+ true
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -7,19 +7,14 @@ module PostcodeValidation
7
7
  @format_validator = FormatValidator.new
8
8
  @address_match_gateway = address_match_gateway
9
9
  @logger = logger
10
- @errors = []
11
10
  end
12
11
 
13
12
  def execute(postcode:, country:)
13
+ @errors = []
14
14
  check_country(country)
15
15
 
16
- if country == 'SG'
17
- check_postcode_format(postcode_without_spaces(postcode), country)
18
-
19
- if @errors.empty?
20
- return { valid?: true, reason: ['valid_postcode'] }
21
- end
22
- end
16
+ postcode = postcode_without_spaces(postcode)
17
+ return the_postcode_is_valid if use_local_validator?(country) && format_valid_for_country?(country, postcode)
23
18
 
24
19
  check_postcode_format(postcode, country)
25
20
  result = matched_addresses(postcode, country)
@@ -39,7 +34,7 @@ module PostcodeValidation
39
34
  return { valid?: false, reason: @errors } unless @errors.empty?
40
35
 
41
36
  result.each do |address|
42
- return { valid?: true, reason: ['valid_postcode'] } if address.postcode_matches? postcode
37
+ return the_postcode_is_valid if address.postcode_matches? postcode
43
38
  end
44
39
 
45
40
  { valid?: false, reason: ['no_postcode_matches_found'] }
@@ -64,8 +59,24 @@ module PostcodeValidation
64
59
 
65
60
  def check_postcode_format(postcode, country)
66
61
  return if country.nil?
62
+ @errors << 'invalid_format' unless format_valid_for_country?(country, postcode)
63
+ end
64
+
65
+ def format_valid_for_country?(country, postcode)
67
66
  validator = @format_validator.for(country)
68
- @errors << 'invalid_format' if !validator.valid?(postcode)
67
+ format_valid?(postcode, validator)
68
+ end
69
+
70
+ def format_valid?(postcode, validator)
71
+ validator.valid?(postcode)
72
+ end
73
+
74
+ def use_local_validator?(country)
75
+ format_check_only?(@format_validator.for(country))
76
+ end
77
+
78
+ def format_check_only?(validator)
79
+ validator.format_check_only?
69
80
  end
70
81
 
71
82
  def gracefully_handle_error(error)
@@ -76,6 +87,10 @@ module PostcodeValidation
76
87
  def postcode_without_spaces(postcode)
77
88
  postcode.gsub(' ', '')
78
89
  end
90
+
91
+ def the_postcode_is_valid
92
+ { valid?: true, reason: ['valid_postcode'] }
93
+ end
79
94
  end
80
95
  end
81
96
  end
@@ -1,3 +1,3 @@
1
1
  module PostcodeValidation
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postcode_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig J. Bass
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-18 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -140,10 +140,13 @@ files:
140
140
  - lib/postcode_validation/use_case/validate_address/format_validators/be_postcode_validator.rb
141
141
  - lib/postcode_validation/use_case/validate_address/format_validators/fr_postcode_validator.rb
142
142
  - lib/postcode_validation/use_case/validate_address/format_validators/gb_postcode_validator.rb
143
+ - lib/postcode_validation/use_case/validate_address/format_validators/in_postcode_validator.rb
143
144
  - lib/postcode_validation/use_case/validate_address/format_validators/nl_postcode_validator.rb
144
145
  - lib/postcode_validation/use_case/validate_address/format_validators/no_op_postcode_validator.rb
145
146
  - lib/postcode_validation/use_case/validate_address/format_validators/regex_validator.rb
146
147
  - lib/postcode_validation/use_case/validate_address/format_validators/sg_postcode_validator.rb
148
+ - lib/postcode_validation/use_case/validate_address/format_validators/use_external_postcode_validator.rb
149
+ - lib/postcode_validation/use_case/validate_address/format_validators/use_format_check_only.rb
147
150
  - lib/postcode_validation/version.rb
148
151
  - postcode_validation.gemspec
149
152
  homepage:
@@ -166,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
169
  version: '0'
167
170
  requirements: []
168
171
  rubyforge_project:
169
- rubygems_version: 2.6.8
172
+ rubygems_version: 2.5.2
170
173
  signing_key:
171
174
  specification_version: 4
172
175
  summary: Provides really basic postcode validation (intended for eCommerce platforms).