Module: FerryCore::Inflector

Extended by:
Inflector
Included in:
Inflector
Defined in:
lib/locomotive/core_extensions/inflector.rb

Instance Method Summary collapse

Instance Method Details

#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object

Converts the string to UpperCamelCase



7
8
9
10
11
12
13
14
15
16
# File 'lib/locomotive/core_extensions/inflector.rb', line 7

def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  str = lower_case_and_underscored_word.to_s
  if first_letter_in_uppercase then
    str.gsub(/\/(.?)/) { "::#{$1.upcase}" }.
        gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    str[0].chr.downcase + 
           camelize(lower_case_and_underscored_word)[1..-1]
  end   
end

#underscore(camel_cased_word) ⇒ Object

the reverse to camelcase



19
20
21
22
23
24
25
# File 'lib/locomotive/core_extensions/inflector.rb', line 19

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