URL - friendly slugify in Ruby
Gemfile :
gem 'ruby-slugify', '~> 1.0'
Installing the Gem :
gem install ruby-slugify
By default the language is taken as English
> newObj = RubySlugify.new("---Hello-World!---")
> slug = newObj.createSlug()
> puts slug
hello-world
Specifying other languages can be done using ISO 2 Letter Language Codes. The following are supported :
- English - en
- Spanish - es
- Polish - po
- Finnish - fi
- Dutch - nl
- Greek - gr, el, ell
- German - de
- Turkish - tr
> newObj = RubySlugify.new("Diese & Dass", "de")
> slug = newObj.createSlug()
> puts slug
diese-und-dass
You can also provide a custom map
> customMap = {
"ball" => "bat",
"ike" => "hello"
}
> newObj = RubySlugify.new("I like my ball", "en", customMap)
> slug = newObj.createSlug()
> puts slug
i-lhello-my-bat
To check if a string is slugified use the isSlug method
> RubySlugify.isSlug("sjjdj##d")
false
This project is released under the MIT License.