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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04debe8d04f23737c37f0245a89db018f2cc1cad8047513ed6efdc25f264b0e9
4
- data.tar.gz: 86e9e38618a9f539d1ce4150f7435cccc64e498bab4471f1708c66a89b60ae8f
3
+ metadata.gz: 422b2acba3b514159146fc9acd6aae2d54727010a7700e5d29b93d3e9708acb2
4
+ data.tar.gz: d56d0dc179b963c7186bcd32c973a178498c23315e56a3201056d12c130cfc16
5
5
  SHA512:
6
- metadata.gz: f56595def1fa147c29b29c381b5062b266bbe68fbd8296618553aea44f72f2eb87d615037bed90603577ef0832a61714a068756d3c92ff82bc90bed31698c311
7
- data.tar.gz: a09b8dce9a653949d4c9f6253dee360d0368c4cc80d8020783bbf849dbc8e8b5d8a58978491ee39c397c19c80ed04490caee6b7f14896bca0047e14c12631ebe
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.2.0)
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.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -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
- raise "Zip code provided #{zip_code} is invalid. Must be a 5 digits number" if !zip_code || zip_code.to_s.length != 5
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.0
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-05-27 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