Module: Animoto::Support::String

Defined in:
lib/animoto/support/string.rb

Instance Method Summary collapse

Instance Method Details

#camelizeString

Transforms this string from underscore-form to camel case. Capitalizes the first letter.

Examples:

"this_is_a_underscored_string" # => "ThisIsAUnderscoredString"

Returns:

  • (String)

    the camel case form of this string



12
13
14
# File 'lib/animoto/support/string.rb', line 12

def camelize
  self.gsub(/(?:^|_)(.)/) { $1.upcase }
end

#underscoreString

Transforms this string from camel case to underscore-form. Downcases the entire string.

Examples:

"ThisIsACamelCasedString" # => "this_is_a_camel_cased_string"

Returns:

  • (String)

    the underscored form of this string



23
24
25
# File 'lib/animoto/support/string.rb', line 23

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