mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
17 lines
448 B
Ruby
17 lines
448 B
Ruby
# frozen_string_literal: false
|
|
|
|
# Converts strings for use as parts of a URL. The input can contain non-roman/non-UTF8 characters
|
|
# and the output will still be valid (including some transliteration). Examples:
|
|
#
|
|
# "Top Cat!" -> "top-cat"
|
|
# "Père Noël" -> "pere-noel"
|
|
# "你好" -> "ni-hao"
|
|
|
|
require "stringex/unidecoder"
|
|
|
|
class UrlGenerator
|
|
def self.to_url(string)
|
|
Stringex::Unidecoder.decode(string.to_s).parameterize
|
|
end
|
|
end
|