class ZohoHub::StringUtils

Public Class Methods

camelize(text) click to toggle source
# File lib/zoho_hub/string_utils.rb, line 18
def camelize(text)
  result = text.split(/[_\s]/)

  return result.first if result.size == 1

  result.map(&:capitalize).join
end
demodulize(text) click to toggle source
# File lib/zoho_hub/string_utils.rb, line 6
def demodulize(text)
  text.split('::').last
end
pluralize(text) click to toggle source
# File lib/zoho_hub/string_utils.rb, line 10
def pluralize(text)
  if defined?(ActiveSupport::Inflector)
    ActiveSupport::Inflector.pluralize(text)
  else
    "#{text}s"
  end
end
underscore(text) click to toggle source
# File lib/zoho_hub/string_utils.rb, line 26
def underscore(text)
  return text unless text =~ /[A-Z-]/

  result = text.dup
  result.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  result.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  result.tr!('-', '_')
  result.downcase!
  result
end