module Plaza::Inflector

Public Instance Methods

classify(table_name) click to toggle source
# File lib/plaza/inflector.rb, line 5
def classify(table_name)
  singularize(table_name.split('_').map(&:capitalize).join)
end
pluralize(str) click to toggle source
# File lib/plaza/inflector.rb, line 9
def pluralize(str)
  str.strip!
  str.gsub!(/y$/,'ies')
  str << 's' unless str[-1] == 's'
  str
end
singularize(str) click to toggle source
# File lib/plaza/inflector.rb, line 16
def singularize(str)
  str.strip!
  str.gsub!(/ies$/,'y')
  str.chomp('s')
end
tableize(str) click to toggle source
# File lib/plaza/inflector.rb, line 22
def tableize(str)
  pluralize(underscore(str))
end
underscore(str) click to toggle source
# File lib/plaza/inflector.rb, line 26
def underscore(str)
  return str unless str =~ /[A-Z-]|::/
  word = str.to_s.gsub(/::/, '/')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end