module SlugLess
Constants
- LATIN_DIACRITICS1
- VERSION
Public Instance Methods
remove_special_characters(text)
click to toggle source
# File lib/slug_less/to_slug.rb, line 40 def remove_special_characters(text) text.gsub!(/[^a-z0-9-]/, '') text end
sanitize(text)
click to toggle source
# File lib/slug_less/to_slug.rb, line 32 def sanitize(text) text.downcase! text.gsub! ' ','-' text.gsub!(/-+/, '-') text.gsub!(/\A-|-\z/, '') text end
substitute_characters(text, char_table = SlugLess::LATIN_DIACRITICS1)
click to toggle source
# File lib/slug_less/to_slug.rb, line 19 def substitute_characters(text, char_table = SlugLess::LATIN_DIACRITICS1) characters_to_change = char_table.values slug_friendly_characters = char_table.keys characters_to_change.each_with_index do |set, idx| text.chars.each do |char| text.gsub!(char, slug_friendly_characters[idx]) if set.include?(char) end end text end
to_slug()
click to toggle source
# File lib/slug_less/to_slug.rb, line 4 def to_slug text = self.dup transliterate(text) sanitize(text) remove_special_characters(text) end
transliterate(text)
click to toggle source
# File lib/slug_less/to_slug.rb, line 13 def transliterate(text) # TODO: figure out how to make this so others can choose which # dictionaries to load or even load custom ones. substitute_characters(text) end