Module: Slugity::Util

Defined in:
lib/slugity/utilities.rb

Class Method Summary collapse

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

Parameters:

Returns:

  • (String)

    the string without begining and ending spaces



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