Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/octocore-cassandra/utils.rb
Instance Method Summary collapse
-
#to_slug ⇒ Object
Create a custom method to convert strings to Slugs.
Instance Method Details
#to_slug ⇒ Object
Create a custom method to convert strings to Slugs
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/octocore-cassandra/utils.rb', line 60 def to_slug #strip the string ret = self.strip #blow away apostrophes ret.gsub!(/['`]/,'') # @ --> at, and & --> and ret.gsub!(/\s*@\s*/, ' at ') ret.gsub!(/\s*&\s*/, ' and ') #replace all non alphanumeric, underscore or periods with underscore ret.gsub!(/\s*[^A-Za-z0-9\.\-]\s*/, '_') #convert double underscores to single ret.gsub!(/_+/,'_') #strip off leading/trailing underscore ret.gsub!(/\A[_\.]+|[_\.]+\z/,'') ret end |