Sha256: bf747d6b3cc733e65354f8cfcee5e8ca5ebe9ca7930dd7e25ecb16de7fe7f469
Contents?: true
Size: 842 Bytes
Versions: 6
Compression:
Stored size: 842 Bytes
Contents
# frozen_string_literal: true module SolidusBraintree module CountryMapper extend ActiveSupport::Concern USA_VARIANTS = [ "the united states of america", "united states of america", "the united states", "united states", "us of a", "u.s.a.", "usa", "u.s.", "us" ].freeze CANADA_VARIANTS = [ "canada", "ca" ].freeze # Generates a hash mapping each variant of the country name to the same ISO # ie: { "usa" => "US", "united states" => "US", "canada" => "CA", ... } COUNTRY_MAP = { USA_VARIANTS => "US", CANADA_VARIANTS => "CA" }.flat_map { |variants, iso| variants.map { |v| [v, iso] } }.to_h included do def iso_from_name(country_name) COUNTRY_MAP[country_name.downcase.strip] end end end end
Version data entries
6 entries across 6 versions & 1 rubygems