Module: CostaRicaAddressUtils
- Extended by:
- CostaRica
- Defined in:
- lib/costa_rica_address_utils.rb,
lib/costa_rica_address_utils/errors.rb,
lib/costa_rica_address_utils/version.rb,
lib/costa_rica_address_utils/guatemala.rb,
lib/costa_rica_address_utils/costa_rica.rb
Overview
TODO: find way to optimize dataset loading
Defined Under Namespace
Modules: CostaRica, Guatemala Classes: InvalidData
Constant Summary collapse
- SUPPORTED_COUNTRIES =
%i[costa_rica guatemala].freeze
- VALID_INPUT_PROVIDERS =
%i[shopify brightpearl].freeze
- VERSION =
'0.5.0'
Constants included from CostaRica
CostaRica::JSON_FILE_PATH, CostaRica::LOCATIONS_DATASET, CostaRica::NEW_JSON_FILE_PATH, CostaRica::NEW_LOCATIONS_DATASET
Class Method Summary collapse
-
.build_address_from_provider(address:, provider:) ⇒ Object
Build a Costa Rica address from an address of an external provider (Shopify, Brightpearl, etc) shopify.dev/api/admin-graphql/2022-10/objects/mailingaddress api-docs.brightpearl.com/contact/postal-address/get.html Standarized format locationLevelX for the address Province/Department, Municipality/Canton, District/Parish since they are named differently in each country.
-
.for_country(country) ⇒ Object
TODO: merge the methods from both countries using new dataset for costa rica instead of previous one Newer files contains a standarized format for fields.
Methods included from CostaRica
address_valid?, fetch_address_data, fetch_address_from_zip, fetch_address_from_zip!, zip_valid?
Class Method Details
.build_address_from_provider(address:, provider:) ⇒ Object
Build a Costa Rica address from an address of an external provider (Shopify, Brightpearl, etc) shopify.dev/api/admin-graphql/2022-10/objects/mailingaddress api-docs.brightpearl.com/contact/postal-address/get.html Standarized format locationLevelX for the address Province/Department, Municipality/Canton, District/Parish since they are named differently in each country
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/costa_rica_address_utils.rb', line 35 def self.build_address_from_provider(address:, provider:) case provider when :shopify { name: address.name, # Customer name address1: address.address1, locationLevel1: address.province, locationLevel2: address.city, locationLevel3: address.address2, zip: address.zip, national_id: address.company, phone: address.phone } when :brightpearl { name: address['addressFullName'], # Customer name address1: address['addressLine1'], locationLevel1: address['addressLine4'], locationLevel2: address['addressLine3'], locationLevel3: address['addressLine2'], zip: address['postalCode'], national_id: address['companyName'], phone: address['telephone'] } else raise InvalidData("Invalid provider, valid providers are: #{VALID_INPUT_PROVIDERS}") end end |
.for_country(country) ⇒ Object
TODO: merge the methods from both countries using new dataset for costa rica instead of previous one Newer files contains a standarized format for fields.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/costa_rica_address_utils.rb', line 19 def self.for_country(country) case country.to_sym when :costa_rica CostaRicaAddressUtils::CostaRica when :guatemala CostaRicaAddressUtils::Guatemala else raise ArgumentError, "Unsupported country: #{country}. Supported countries are: #{SUPPORTED_COUNTRIES}" end end |