Class: Cropio::StringInflector

Inherits:
Object
  • Object
show all
Defined in:
lib/cropio/misc/string_inflector.rb

Class Method Summary collapse

Class Method Details

.pluralize(string) ⇒ Object

simple implementation - for resources plural form only



14
15
16
17
18
19
20
# File 'lib/cropio/misc/string_inflector.rb', line 14

def pluralize(string)
  if string[-1] == 'y'
    "#{ string[0..(string.length - 2)] }ies"
  else
    "#{ string }s"
  end
end

.underscore(string) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/cropio/misc/string_inflector.rb', line 4

def underscore(string)
  string
    .gsub(/::/, '/')
    .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
    .gsub(/([a-z\d])([A-Z])/,'\1_\2')
    .tr("-", "_")
    .downcase
end