Module: StringHelper

Extended by:
StringHelper
Included in:
StringHelper
Defined in:
lib/appengine-mapreduce/string_helpers.rb

Instance Method Summary collapse

Instance Method Details

#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



4
5
6
# File 'lib/appengine-mapreduce/string_helpers.rb', line 4

def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end

#underscore(camel_cased_word) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/appengine-mapreduce/string_helpers.rb', line 8

def underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end