Sha256: 82c38af9d147a67dcb86ff60833567b76c28fc2bfc858567829154179ed7147e
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
module WorldFlags module CountryUtil def country_label code, locale WorldFlags.country code, locale end def countries @countries ||= Countries.new end def country code = :us, locale = :en locale ||= default_locale_used locale_countries_map = countries_map[locale] || countries_map[default_locale_used] locale_countries_map = countries_map[:en] if locale_countries_map.blank? raise "No country-locale map defined for locale: #{locale} or :en in #{countries.inspect}" if locale_countries_map.blank? # raise("No country map defined for country code: #{code} in #{locale_countries_map[code]}") locale_countries_map[code] ? locale_countries_map[code] : locale_countries_map[default_code_used] rescue Exception => e raise e if WorldFlags.raise_error? "Undefined" end def countries= countries raise ArgumentError, "Must be a hash, was: #{countries}" unless countries.kind_of?(Hash) @countries = countries end def countries_map @countries_map ||= begin active_locales.inject({}) do |res, loc| res[loc] = find_country_map(loc) res end end end def find_country_map loc countries.respond_to?(loc) ? countries.send(loc) : languages.send(locale(loc)) rescue countries.send(default_locale_used) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
world-flags-0.3.4 | lib/world_flags/country_util.rb |