Created
February 12, 2021 12:41
-
-
Save wbotelhos/3aaff949c534782e2296bdbb31b67444 to your computer and use it in GitHub Desktop.
Country Code to Emoji Flag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def country_code_to_flag(country_code) | |
code = country_code.to_s.upcase | |
return unless code =~ /\A[A-Z]{2}\z/ | |
code.codepoints.map { |codepoint| (codepoint + 127_397).chr(Encoding::UTF_8) }.join | |
end | |
country_code_to_flag("BR") | |
# => "🇧🇷" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment