class AnchorRb

Ruby transcription of: github.com/bryanbraun/anchorjs/blob/master/anchor.js

Public Class Methods

convert(rough_text) click to toggle source
# File lib/anchorrb.rb, line 4
def self.convert(rough_text)
  unsafe_chars = %r{[\\\[\]\+\$\?& ,:;=@"{}#|^~`\%!./()*]}
  tidy_text = rough_text.delete("'")
  tidy_text = tidy_text.gsub(unsafe_chars, '-')
  tidy_text = tidy_text.gsub(/-{2,}/, '-')
  tidy_text = tidy_text[0, 64]
  tidy_text = tidy_text.gsub(/^-+|-+$/, '')
  tidy_text.downcase
end