module EndiciaLabelServer::Util

Public Class Methods

camelize(value) click to toggle source
# File lib/endicia_label_server/util.rb, line 4
def camelize(value)
  value.to_s.split('_').map { |v| capitalize_with_id_exception(v) }.join
end
capitalize_with_id_exception(value) click to toggle source
# File lib/endicia_label_server/util.rb, line 8
def capitalize_with_id_exception(value)
  (value == 'id') ? 'ID' : value.capitalize
end
singularize(word) click to toggle source
# File lib/endicia_label_server/util.rb, line 12
def singularize(word)
  if word =~ /([a-zA-Z]+?)(s\b|\b)/i
    return $1
  else
    return word
  end
end
underscore(word) click to toggle source
# File lib/endicia_label_server/util.rb, line 20
def underscore(word)
  word.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end