def lookup_country_info(hash, code, encoding = Encoding::UTF_8)
      raise InvalidCountryCode, "Invalid country code: #{code.nil? ? 'nil' : code}" unless code.kind_of?(String)

      info = try_with_encoding(code, encoding) {|c| hash[c] }
      return info if info

      raise InvalidCountryCode, "Invalid country code: #{code.encode(Encoding::UTF_8)}"
    end
def lookup_country_info(hash, code, encoding = Encoding::UTF_8)
      raise InvalidCountryCode, "Invalid country code: #{code.nil? ? 'nil' : code}" unless code.kind_of?(String)

      info = try_with_encoding(code, encoding) {|c| hash[c] }
      return info if info

      raise InvalidCountryCode, "Invalid country code: #{code.encode(Encoding::UTF_8)}"
    end
Looks up a given code in the given hash of code to
 {DataSources::CountryInfo} mappings. If the code is found the
 {DataSources::CountryInfo} is returned. Otherwise an {InvalidCountryCode}
 exception is raised.

 @param hash [String, DataSources::CountryInfo] a mapping from ISO 3166-1
   alpha-2 country codes to {DataSources::CountryInfo} instances.
 @param code [String] a country code to lookup.
 @param encoding [Encoding] the encoding used for the country codes in
   `hash`.
 @return [DataSources::CountryInfo] the {DataSources::CountryInfo} instance
   corresponding to `code`.
 @raise [InvalidCountryCode] if `code` was not found in `hash`.