costa_rica_address_utils 0.2.0 → 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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/costa_rica_address_utils/version.rb +1 -1
- data/lib/costa_rica_address_utils.rb +12 -1
- 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: 422b2acba3b514159146fc9acd6aae2d54727010a7700e5d29b93d3e9708acb2
|
|
4
|
+
data.tar.gz: d56d0dc179b963c7186bcd32c973a178498c23315e56a3201056d12c130cfc16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c540062083850af8a8dd1a18d73f8532e873babb23680c3f436d32347602d45e8e6475b515a6c086b0b2d2926fd08fd53eccc31f3bc98b3d46f62918d421c6e
|
|
7
|
+
data.tar.gz: 7f0cad040f239326935192decffd4c752d7849bc8444aef279d0cfdc9abe66c597def359e2b822e0ce4f24936d5ba949f7674f8743e21b5ff7a60915b3b8b4cd
|
data/Gemfile.lock
CHANGED
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).
|
|
@@ -37,7 +37,7 @@ module CostaRicaAddressUtils
|
|
|
37
37
|
|
|
38
38
|
# Get one address information from a zip code
|
|
39
39
|
def self.fetch_address_from_zip(zip_code)
|
|
40
|
-
|
|
40
|
+
return nil unless zip_valid?(zip_code)
|
|
41
41
|
zip_code_s = zip_code.to_s
|
|
42
42
|
LOCATIONS_DATASET.each do |province, province_data|
|
|
43
43
|
province_data["cantons"].each do |canton, canton_data|
|
|
@@ -57,6 +57,11 @@ module CostaRicaAddressUtils
|
|
|
57
57
|
return nil
|
|
58
58
|
end
|
|
59
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
|
+
|
|
60
65
|
def self.address_valid?(province:, canton:, district:)
|
|
61
66
|
is_valid = true
|
|
62
67
|
begin
|
|
@@ -69,6 +74,10 @@ module CostaRicaAddressUtils
|
|
|
69
74
|
return is_valid
|
|
70
75
|
end
|
|
71
76
|
|
|
77
|
+
def self.zip_valid?(zip_code)
|
|
78
|
+
!!zip_code && zip_code.to_s.length == 5
|
|
79
|
+
end
|
|
80
|
+
|
|
72
81
|
# Build a Costa Rica address from an address of an external provider (Shopify, Brightpearl, etc)
|
|
73
82
|
# https://shopify.dev/api/admin-graphql/2022-10/objects/mailingaddress
|
|
74
83
|
# https://api-docs.brightpearl.com/contact/postal-address/get.html
|
|
@@ -104,4 +113,6 @@ module CostaRicaAddressUtils
|
|
|
104
113
|
raise InvalidData("Invalid provider, valid providers are: #{VAlID_PROVIDERS}")
|
|
105
114
|
end
|
|
106
115
|
end
|
|
116
|
+
|
|
117
|
+
private
|
|
107
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.2.
|
|
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: 2024-
|
|
11
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: byebug
|