Sha256: 22aef5fc79c871aa1d203867242109718d6550a4bc31293168409e7001d5ffa2
Contents?: true
Size: 848 Bytes
Versions: 5
Compression:
Stored size: 848 Bytes
Contents
# frozen_string_literal: true module SolidusPaypalBraintree 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
5 entries across 5 versions & 1 rubygems