Module: Bootscaf::Utils

Defined in:
lib/bootscaf/utils.rb

Class Method Summary collapse

Class Method Details

.singularize(str) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bootscaf/utils.rb', line 3

def self.singularize(str)
  unless str == str.gsub(/([^aeiouy])ies$/i, '\1y')
    return str.gsub(/([^aeiouy])ies$/i, '\1y')
  end
  unless str == str.gsub(/([^aeiouy]o)es$/, '\1')
    return str.gsub(/([^aeiouy]o)es$/, '\1')
  end
  unless str == str.gsub(/([sxz]|[cs]h)es$/, '\1')
    return str.gsub(/([sxz]|[cs]h)es$/, '\1')
  end
  unless str == str.gsub(/(ss)$/i, '\1')
    return str.gsub(/(ss)$/i, '\1')
  end
  unless str == str.gsub(/s$/i, '')
    return str.gsub(/s$/i, '')
  end
  return str
end