ca_postal_code 0.2.0 → 0.3.0

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: 74e23617eab8b83ff3803b444f697de1d8ce0447446caa0c23aa205582f4f28c
4
- data.tar.gz: fcba68f76741640a368e4b299a05e6cb519c1c413965929beab6daa345a374f4
3
+ metadata.gz: 66677149dbc296b6a8c1861898aa7083ca454c253d440742e53f41b0116ddd6d
4
+ data.tar.gz: b81e91e584af729de3bd05c9a8ef58b80583aa562d194cc742131be5a2a1ea8d
5
5
  SHA512:
6
- metadata.gz: 29f745dd7c28c4f0cb11ce71efca289232d913469ff7ea6efb1c5bc3db7e5fbc98c0df9e0762ad64ef0dffebaf985594cf0dca76bd5560c27d92b325a7f83dd7
7
- data.tar.gz: e114ca30469b342af67b21966a6f28338e9985d009ca195dd835d516139a967fceb51e3d584a4c02486e119b37aefa7ad0c6a8fe132501927423d8d2b998d0bb
6
+ metadata.gz: 753a836aaa71e3949be86d120ff950f28da4a47bbd05f609b3794975158a4f945d5d8f92dafa7838b4050691981823b51bed63f6326e33d4d1a5ccd80a19cc78
7
+ data.tar.gz: 20533950465b7ea1c97ab55f4cd58e197a97e825f0f66965aac359a2a12ead8c2f56bf412f78100397fc4ab87bf3b80689470e92f8a9f616a175a24a8514ced5
data/Gemfile.lock CHANGED
@@ -7,35 +7,35 @@ GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  coderay (1.1.3)
10
- diff-lcs (1.4.4)
10
+ diff-lcs (1.5.0)
11
11
  interception (0.5)
12
12
  method_source (1.0.0)
13
- pry (0.13.1)
13
+ pry (0.14.2)
14
14
  coderay (~> 1.1)
15
15
  method_source (~> 1.0)
16
16
  pry-rescue (1.5.2)
17
17
  interception (>= 0.5)
18
18
  pry (>= 0.12.0)
19
- rake (13.0.1)
20
- rspec (3.9.0)
21
- rspec-core (~> 3.9.0)
22
- rspec-expectations (~> 3.9.0)
23
- rspec-mocks (~> 3.9.0)
24
- rspec-core (3.9.2)
25
- rspec-support (~> 3.9.3)
26
- rspec-expectations (3.9.2)
19
+ rake (13.0.6)
20
+ rspec (3.12.0)
21
+ rspec-core (~> 3.12.0)
22
+ rspec-expectations (~> 3.12.0)
23
+ rspec-mocks (~> 3.12.0)
24
+ rspec-core (3.12.1)
25
+ rspec-support (~> 3.12.0)
26
+ rspec-expectations (3.12.2)
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.9.0)
29
- rspec-mocks (3.9.1)
28
+ rspec-support (~> 3.12.0)
29
+ rspec-mocks (3.12.3)
30
30
  diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.9.0)
32
- rspec-support (3.9.3)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-support (3.12.0)
33
33
 
34
34
  PLATFORMS
35
35
  ruby
36
36
 
37
37
  DEPENDENCIES
38
- bundler (~> 1.16)
38
+ bundler (~> 2.4)
39
39
  ca_postal_code!
40
40
  pry
41
41
  pry-rescue
@@ -43,4 +43,4 @@ DEPENDENCIES
43
43
  rspec (~> 3.0)
44
44
 
45
45
  BUNDLED WITH
46
- 2.2.22
46
+ 2.4.8
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jonathan Allard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -73,7 +73,7 @@ In your Gemfile:
73
73
 
74
74
  Or install it yourself:
75
75
 
76
- $ gem install ca_postal_code
76
+ gem install ca_postal_code
77
77
 
78
78
  ## Development
79
79
  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.
@@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = CAPostalCode::VERSION
9
9
  spec.authors = ["Jonathan Allard"]
10
10
  spec.email = ["jonathan@allard.io"]
11
+ spec.license = "MIT"
11
12
 
12
13
  spec.summary = %q{Guesses the Canadian province or territory (region) based on the postal code.}
13
14
  # spec.description = %q{Write a longer description or delete this line.}
@@ -21,7 +22,9 @@ Gem::Specification.new do |spec|
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- spec.add_development_dependency "bundler", "~> 1.16"
25
+
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.4"
25
28
  spec.add_development_dependency "rake", "~> 13.0"
26
29
  spec.add_development_dependency "rspec", "~> 3.0"
27
30
 
@@ -1,59 +1,30 @@
1
1
  module CAPostalCode
2
2
  module RegionGuessing
3
-
4
- REGIONS = {
5
- NL: ?A,
6
- NS: ?B,
7
- PE: ?C,
8
- NB: ?E,
9
- QC: [?G, ?H, ?J],
10
- ON: [?K, ?L, ?M, ?N, ?P],
11
- MB: ?R,
12
- SK: ?S,
13
- AB: ?T,
14
- BC: ?V,
15
- NU: /^X0[A-C]/,
16
- NT: [/^X0[EG]/, /^X1A/],
17
- YT: ?Y,
3
+ PATTERNS = {
4
+ /^A/ => "NL",
5
+ /^B/ => "NS",
6
+ /^C/ => "PE",
7
+ /^E/ => "NB",
8
+ /^[GHJ]/ => "QC",
9
+ /^[KLMNP]/ => "ON",
10
+ /^R/ => "MB",
11
+ /^S/ => "SK",
12
+ /^T/ => "AB",
13
+ /^V/ => "BC",
14
+ /^X0[A-C]/ => "NU",
15
+ /^X0[EG]|^X1A/ => "NT",
16
+ /^Y/ => "YT",
18
17
  }
19
18
 
20
19
  # Guesses province or territory based on postal code first characters.
21
20
  #
22
21
  # Output is defined for valid, normalized postal codes only.
23
22
  def guess_region(string)
24
- entry = region_patterns.detect do |pattern, region|
23
+ entry = PATTERNS.detect do |pattern, region|
25
24
  pattern.match?(string)
26
25
  end
27
26
 
28
27
  entry[1] if entry
29
28
  end
30
-
31
- # Lists the patterns the library will use. It is made public only to
32
- # make the implementation visible.
33
- def region_patterns
34
- @@region_patterns
35
- end
36
-
37
- private
38
-
39
- def self.add_pattern(pattern, region)
40
- unless pattern.is_a?(Regexp)
41
- pattern = Regexp.new("^" + pattern)
42
- end
43
-
44
- @@region_patterns[pattern] = region.to_s
45
- end
46
-
47
- @@region_patterns = {}
48
-
49
- REGIONS.each do |region, patterns|
50
- unless patterns.is_a?(Array)
51
- patterns = [patterns]
52
- end
53
-
54
- patterns.each do |pattern|
55
- add_pattern(pattern, region)
56
- end
57
- end
58
29
  end
59
30
  end
@@ -1,3 +1,3 @@
1
1
  module CAPostalCode
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -29,9 +29,8 @@ module CAPostalCode
29
29
  #
30
30
  # Will return `nil` if the normalized string does not have 6 characters.
31
31
  def self.normalize(string)
32
- string.strip!
32
+ string.gsub!(/[^a-zA-Z0-9]/, '')
33
33
  string.upcase!
34
- string.gsub!(/\W/, '')
35
34
 
36
35
  return unless string.length == 6
37
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ca_postal_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Allard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-27 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.4'
20
20
  type: :development
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: '1.16'
26
+ version: '2.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,6 +92,7 @@ files:
92
92
  - ".travis.yml"
93
93
  - Gemfile
94
94
  - Gemfile.lock
95
+ - LICENSE.md
95
96
  - README.md
96
97
  - Rakefile
97
98
  - bin/console
@@ -102,7 +103,8 @@ files:
102
103
  - lib/ca_postal_code/region_guessing.rb
103
104
  - lib/ca_postal_code/version.rb
104
105
  homepage: https://github.com/joallard/ca-postal-code
105
- licenses: []
106
+ licenses:
107
+ - MIT
106
108
  metadata: {}
107
109
  post_install_message:
108
110
  rdoc_options: []
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  - !ruby/object:Gem::Version
120
122
  version: '0'
121
123
  requirements: []
122
- rubygems_version: 3.2.22
124
+ rubygems_version: 3.4.1
123
125
  signing_key:
124
126
  specification_version: 4
125
127
  summary: Guesses the Canadian province or territory (region) based on the postal code.