validates_zipcode 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: ad8c2f2c935a1571e8824200d9494c7d8d95ed6292eec99ddd135b8df5389f11
4
- data.tar.gz: ad38314b05f03aac01b7ef9800e135eb99afe70dc03610609fb9aa67b5c26a88
3
+ metadata.gz: 9d69de112628ab38fe5ec60e90d96f49601f988de22528de0de4286fcb080d56
4
+ data.tar.gz: 4bddb4ac3fdb64fa8013489ee4fa6611970feb97db546e3da1a46887ef26b493
5
5
  SHA512:
6
- metadata.gz: 34b5cf552795e382cf3a17f60898a4124bac5c4bc643f7c8996bbd2df9b442f62f8bae4ccb024f5332dd26698bfd3413f3f1d8b930a68225e388d17497c38ddb
7
- data.tar.gz: c1cdd89cccb0966f28c1dd27c166097529873ac0a5662ebbf11f15f18a1d04ded857857a2ef858b88403b20988fa6f160d89a2409723ab82b8b29f4ff6866295
6
+ metadata.gz: 7fe6dfdaefe75178df3f5fdebd9841fcbd2ef6179f2565f0d6aa410ad34df62b3789b95e0318c989b404367324e176aad6e82adeccf6445766b108107f889a2c
7
+ data.tar.gz: 434ea691cf005b4e3b14d406e58ac343f2ba01378fae35403c18b5a8fbf3e3276aa17fb6004bda6704e6578d8799329e441a0a0e33510ddbd712afda42fc32f5
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.3.2
6
+
7
+ - Adds formatter for CA ~ @devthiago
8
+
5
9
  ## 0.3.1
6
10
 
7
11
  - Removes forbidden combinations in the Netherlands ~ @gerard76
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- validates_zipcode (0.3.1)
4
+ validates_zipcode (0.3.2)
5
5
  activemodel (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- validates_zipcode (0.3.1)
4
+ validates_zipcode (0.3.2)
5
5
  activemodel (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- validates_zipcode (0.3.1)
4
+ validates_zipcode (0.3.2)
5
5
  activemodel (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -14,7 +14,7 @@ GIT
14
14
  PATH
15
15
  remote: ..
16
16
  specs:
17
- validates_zipcode (0.3.1)
17
+ validates_zipcode (0.3.2)
18
18
  activemodel (>= 4.2.0)
19
19
 
20
20
  GEM
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  module ValidatesZipcode
2
3
  class Formatter
4
+ WORD_CHAR_AND_DIGIT = /[A-Z0-9]/.freeze
3
5
 
4
6
  ZIPCODES_TRANSFORMATIONS = {
5
7
  AT: ->(z) { z.scan(/\d/).join },
8
+ CA: ->(z) { z.upcase.scan(WORD_CHAR_AND_DIGIT).insert(3, ' ').join },
6
9
  CZ: ->(z) { z.scan(/\d/).insert(3, ' ').join },
7
- DE: ->(z) { z.scan(/\d/).join.rjust(5, "0") },
8
- GB: ->(z) { z.upcase.scan(/[A-Z0-9]/).insert(-4, ' ').join },
9
- NL: ->(z) { z.upcase.scan(/[A-Z0-9]/).insert(4, ' ').join },
10
+ DE: ->(z) { z.scan(/\d/).join.rjust(5, '0') },
11
+ GB: ->(z) { z.upcase.scan(WORD_CHAR_AND_DIGIT).insert(-4, ' ').join },
12
+ NL: ->(z) { z.upcase.scan(WORD_CHAR_AND_DIGIT).insert(4, ' ').join },
10
13
  PL: ->(z) { z.scan(/\d/).insert(2, '-').join },
11
14
  SK: :CZ,
12
15
  UK: :GB,
@@ -15,7 +18,7 @@ module ValidatesZipcode
15
18
  digits.insert(5, '-') if digits.count > 5
16
19
  digits.join
17
20
  }
18
- }
21
+ }.freeze
19
22
 
20
23
  def initialize(args = {})
21
24
  @zipcode = args.fetch(:zipcode).to_s
@@ -33,6 +36,5 @@ module ValidatesZipcode
33
36
  @zipcode.strip
34
37
  end
35
38
  end
36
-
37
39
  end
38
- end
40
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ValidatesZipcode
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
@@ -2,6 +2,12 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe ValidatesZipcode::Formatter, '#format' do
5
+ context 'Canada' do
6
+ it { check_format('CA', 'l3b3z6' => 'L3B 3Z6') }
7
+ it { check_format('ca', 'V2r-1c8' => 'V2R 1C8') }
8
+ it { check_format(:ca, 'g9a 5w1' => 'G9A 5W1') }
9
+ end
10
+
5
11
  context 'Czech' do
6
12
  it { check_format('CZ', '12000' => '120 00') }
7
13
  it { check_format(:cz, '721 00' => '721 00') }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_zipcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Gil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-19 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel