costa_rica_address_utils 0.1.02 → 0.2.1

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: 6d7671d4fcae7c2b653dfc0e0a1c21efb653c6a50a2b23d156ec05b82780b4ef
4
- data.tar.gz: 4302d34bd690087a8297e306d35358f0663191f80312dbd11e8a80624ef9a495
3
+ metadata.gz: 422b2acba3b514159146fc9acd6aae2d54727010a7700e5d29b93d3e9708acb2
4
+ data.tar.gz: d56d0dc179b963c7186bcd32c973a178498c23315e56a3201056d12c130cfc16
5
5
  SHA512:
6
- metadata.gz: 330f3a0b91cf8259c330b6cc27dd2b03d08474b3d8bdec8b73a60e8ff6d52cc9a34b2e803311a228654fe175b894723f1655cad50e929740ab4df8e22c7507e8
7
- data.tar.gz: 07f8abbfa8bd4e1d78f0f9cade46534ff517d8f870545c6dcb0066542562d5a369de9db6eb02d03d81f12e7af0e34d87afae1cc2951139324cfb394045cfce8f
6
+ metadata.gz: 1c540062083850af8a8dd1a18d73f8532e873babb23680c3f436d32347602d45e8e6475b515a6c086b0b2d2926fd08fd53eccc31f3bc98b3d46f62918d421c6e
7
+ data.tar.gz: 7f0cad040f239326935192decffd4c752d7849bc8444aef279d0cfdc9abe66c597def359e2b822e0ce4f24936d5ba949f7674f8743e21b5ff7a60915b3b8b4cd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- costa_rica_address_utils (0.1.02)
4
+ costa_rica_address_utils (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -42,6 +42,8 @@ To install this gem onto your local machine, run `bundle exec rake install`.
42
42
 
43
43
  To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
44
 
45
+ > Remember to execute `bundle exec rake release` on `main` branch
46
+
45
47
  ## Contributing
46
48
 
47
49
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/costa_rica_address_utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/costa_rica_address_utils/blob/master/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CostaRicaAddressUtils
4
- VERSION = "0.1.02"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -35,6 +35,33 @@ module CostaRicaAddressUtils
35
35
  }
36
36
  end
37
37
 
38
+ # Get one address information from a zip code
39
+ def self.fetch_address_from_zip(zip_code)
40
+ return nil unless zip_valid?(zip_code)
41
+ zip_code_s = zip_code.to_s
42
+ LOCATIONS_DATASET.each do |province, province_data|
43
+ province_data["cantons"].each do |canton, canton_data|
44
+ canton_data["districts"].each do |district, district_data|
45
+ if district_data["zip_code"] == zip_code_s
46
+ return {
47
+ province: province,
48
+ canton: canton,
49
+ district: district,
50
+ zip: zip_code_s,
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ return nil
58
+ end
59
+
60
+ def self.fetch_address_from_zip!(zip_code)
61
+ raise "Zip code provided #{zip_code} is invalid. Must be a 5 digits number" unless zip_valid?(zip_code)
62
+ fetch_address_from_zip(zip_code)
63
+ end
64
+
38
65
  def self.address_valid?(province:, canton:, district:)
39
66
  is_valid = true
40
67
  begin
@@ -47,6 +74,9 @@ module CostaRicaAddressUtils
47
74
  return is_valid
48
75
  end
49
76
 
77
+ def self.zip_valid?(zip_code)
78
+ !!zip_code && zip_code.to_s.length == 5
79
+ end
50
80
 
51
81
  # Build a Costa Rica address from an address of an external provider (Shopify, Brightpearl, etc)
52
82
  # https://shopify.dev/api/admin-graphql/2022-10/objects/mailingaddress
@@ -83,4 +113,6 @@ module CostaRicaAddressUtils
83
113
  raise InvalidData("Invalid provider, valid providers are: #{VAlID_PROVIDERS}")
84
114
  end
85
115
  end
116
+
117
+ private
86
118
  end # module CostaRicaAddressUtils
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: costa_rica_address_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.02
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - vicvans20
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-15 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.2.32
72
+ rubygems_version: 3.5.3
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Utils lib to work with Costa Rica addresses.