Module: Slugity::Util
- Defined in:
- lib/slugity/utilities.rb
Class Method Summary collapse
- .normalize_string(string) ⇒ Object
-
.trim_string(string) ⇒ String
Trims begining and ending spaces from the string.
Class Method Details
.normalize_string(string) ⇒ Object
6 7 8 9 10 |
# File 'lib/slugity/utilities.rb', line 6 def normalize_string string trim_string(string.to_s) rescue NoMethodError raise ArgumentError, "You must pass an object that respond to #to_s" end |
.trim_string(string) ⇒ String
Trims begining and ending spaces from the string
17 18 19 20 21 22 23 24 |
# File 'lib/slugity/utilities.rb', line 17 def trim_string string # capture spaces at the begining or end of the string pattern = /(^\s+|\s+$)/ # strip characters that match the pattern string.gsub( pattern, '' ) end |