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 +4 -4
- data/CHANGELOG.md +4 -0
- data/gemfiles/rails_4.2.gemfile.lock +1 -1
- data/gemfiles/rails_5.2.gemfile.lock +1 -1
- data/gemfiles/rails_6.0.gemfile.lock +1 -1
- data/gemfiles/rails_edge.gemfile.lock +1 -1
- data/lib/validates_zipcode/formatter.rb +8 -6
- data/lib/validates_zipcode/version.rb +1 -1
- data/spec/format_zipcode_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d69de112628ab38fe5ec60e90d96f49601f988de22528de0de4286fcb080d56
|
4
|
+
data.tar.gz: 4bddb4ac3fdb64fa8013489ee4fa6611970feb97db546e3da1a46887ef26b493
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fe6dfdaefe75178df3f5fdebd9841fcbd2ef6179f2565f0d6aa410ad34df62b3789b95e0318c989b404367324e176aad6e82adeccf6445766b108107f889a2c
|
7
|
+
data.tar.gz: 434ea691cf005b4e3b14d406e58ac343f2ba01378fae35403c18b5a8fbf3e3276aa17fb6004bda6704e6578d8799329e441a0a0e33510ddbd712afda42fc32f5
|
data/CHANGELOG.md
CHANGED
@@ -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,
|
8
|
-
GB: ->(z) { z.upcase.scan(
|
9
|
-
NL: ->(z) { z.upcase.scan(
|
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
|
data/spec/format_zipcode_spec.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|