You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

37 lines
1.1 KiB

module Admin::LeaderboardHelper
# Turns "SE" into the flag emoji by mapping each letter onto its regional
# indicator symbol. Cheaper than shipping 34 flag SVGs for one admin screen,
# and it degrades to the two letters wherever the font has no flag.
def country_flag(country_code)
code = country_code.to_s.upcase
return "" unless code.match?(/\A[A-Z]{2}\z/)
code.codepoints.map { |c| (c - 65 + 0x1F1E6) }.pack("U*")
end
def leaderboard_country_name(country_code)
t("countries.#{country_code.to_s.downcase}", default: country_code.to_s.upcase)
end
# The badge types the API emits, named the way the brief describes them.
def badge_type_label(type)
{
"new_players" => "New players",
"encouragement" => "Encouragement",
"participation" => "Participation"
}[type.to_s] || type.to_s.humanize
end
# How long the published payload still has before the next API call
# recomputes it. The cache entry carries no expiry we can read back, so this
# is derived from when it was built.
def leaderboard_cache_age(updated_at)
return nil if updated_at.blank?
Time.current - updated_at
end
end