Module: AmazonProductAdvertisingApi::CoreExtensions::String
- Defined in:
- lib/amazon_product_advertising_api/support.rb
Overview
Some extensions to the String class.
Instance Method Summary collapse
-
#camelize(first_letter_in_uppercase = true) ⇒ Object
Converts strings from under_score format to CamelCase.
-
#underscore ⇒ Object
Converts strings from CamelCase format to under_score.
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
Converts strings from under_score format to CamelCase
47 48 49 50 51 52 53 |
# File 'lib/amazon_product_advertising_api/support.rb', line 47 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } else self.first + camelize(self)[1..-1] end end |
#underscore ⇒ Object
Converts strings from CamelCase format to under_score.
56 57 58 59 60 61 62 |
# File 'lib/amazon_product_advertising_api/support.rb', line 56 def underscore self.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |