Module: Savon::CoreExt::String
- Defined in:
- lib/savon/core_ext/string.rb
Instance Method Summary collapse
-
#lower_camelcase ⇒ Object
Returns the String in lowerCamelCase.
-
#snakecase ⇒ Object
Returns the String in snake_case.
-
#starts_with?(prefix) ⇒ Boolean
Returns whether the String starts with a given
prefix
.
Instance Method Details
#lower_camelcase ⇒ Object
Returns the String in lowerCamelCase.
20 21 22 23 24 25 26 |
# File 'lib/savon/core_ext/string.rb', line 20 def lower_camelcase str = dup str.gsub!(/\/(.?)/) { "::#{$1.upcase}" } str.gsub!(/(?:_+|-+)([a-z])/) { $1.upcase } str.gsub!(/(\A|\s)([A-Z])/) { $1 + $2.downcase } str end |
#snakecase ⇒ Object
Returns the String in snake_case.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/savon/core_ext/string.rb', line 8 def snakecase str = dup str.gsub! /::/, '/' str.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2' str.gsub! /([a-z\d])([A-Z])/, '\1_\2' str.tr! ".", "_" str.tr! "-", "_" str.downcase! str end |
#starts_with?(prefix) ⇒ Boolean
Returns whether the String starts with a given prefix
.
29 30 31 32 |
# File 'lib/savon/core_ext/string.rb', line 29 def starts_with?(prefix) prefix = prefix.to_s self[0, prefix.length] == prefix end |