Module: Groovy::Utils

Defined in:
lib/groovy/model.rb

Class Method Summary collapse

Class Method Details

.classify(str) ⇒ Object



40
41
42
# File 'lib/groovy/model.rb', line 40

def self.classify(str)
  str.to_s.gsub(/([A-Z])/, '_\1').split('_').collect! { |w| w.capitalize }.join
end

.pluralize(str) ⇒ Object

category -> categories product -> products



27
28
29
30
# File 'lib/groovy/model.rb', line 27

def self.pluralize(str)
  return str if str[-1] == 's' # already ends with s, assume already plural
  str.to_s.sub(/y$/, 'ie') + 's'
end

.pluralize_and_classify(str) ⇒ Object



32
33
34
# File 'lib/groovy/model.rb', line 32

def self.pluralize_and_classify(str)
  classify(pluralize(str))
end

.singularize(str) ⇒ Object



21
22
23
# File 'lib/groovy/model.rb', line 21

def self.singularize(str)
  str.to_s.sub(/ies$/, 'y').sub(/s$/, '')
end

.underscore(str) ⇒ Object



36
37
38
# File 'lib/groovy/model.rb', line 36

def self.underscore(str)
  str.gsub(/([A-Z])/) { |x| "_#{x.downcase}" }.sub(/^_/, '')
end