Module: ProductTaxonomy::IdentifierFormatter
- Defined in:
- lib/product_taxonomy/identifier_formatter.rb
Class Method Summary collapse
Class Method Details
.format_friendly_id(text) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/product_taxonomy/identifier_formatter.rb', line 6 def format_friendly_id(text) I18n.transliterate(text) .downcase .gsub(%r{[^a-z0-9\s\-_/\.\+#]}, "") .gsub(/[\s\-\.]+/, "_") end |
.format_handle(text) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/product_taxonomy/identifier_formatter.rb', line 13 def format_handle(text) I18n.transliterate(text) .downcase .gsub(%r{[^a-z0-9\s\-_/\+#]}, "") .gsub("+", "-plus-") .gsub("#", "-hashtag-") .gsub("/", "-") .gsub(/[\s\.]+/, "-") .gsub("_-_", "-") .gsub(/(?<!_)_(?!_)/, "-") .gsub(/--+/, "-") .gsub(/\A-+|-+\z/, "") end |