Module: EndiciaLabelServer::Util

Defined in:
lib/endicia_label_server/util.rb

Class Method Summary collapse

Class Method Details

.camelize(value) ⇒ Object



4
5
6
# 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) ⇒ Object



8
9
10
# File 'lib/endicia_label_server/util.rb', line 8

def capitalize_with_id_exception(value)
  (value == 'id') ? 'ID' : value.capitalize
end

.singularize(word) ⇒ Object



12
13
14
15
16
17
18
# 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) ⇒ Object



20
21
22
23
24
25
26
# 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