Class: String
Class Method Summary collapse
-
.random(length = 100) ⇒ Object
Returns a random String of a given
length
.
Instance Method Summary collapse
-
#lower_camelcase ⇒ Object
Returns the String in lowerCamelCase.
-
#map_soap_response ⇒ Object
Translates SOAP response values to more convenient Ruby Objects.
-
#snakecase ⇒ Object
Returns the String in snake_case.
-
#strip_namespace ⇒ Object
Returns the String without namespace.
-
#to_soap_value ⇒ Object
Returns the String as a SOAP request compliant value.
Class Method Details
.random(length = 100) ⇒ Object
Returns a random String of a given length
.
4 5 6 |
# File 'lib/savon/core_ext/string.rb', line 4 def self.random(length = 100) (0...length).map { ("a".."z").to_a[rand(26)] }.join end |
Instance Method Details
#lower_camelcase ⇒ Object
Returns the String in lowerCamelCase.
21 22 23 24 25 26 27 |
# File 'lib/savon/core_ext/string.rb', line 21 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 |
#map_soap_response ⇒ Object
Translates SOAP response values to more convenient Ruby Objects.
35 36 37 38 39 40 |
# File 'lib/savon/core_ext/string.rb', line 35 def map_soap_response return DateTime.parse( self ) if Savon::SOAPDateTimeRegexp === self return true if self.strip.downcase == "true" return false if self.strip.downcase == "false" self end |
#snakecase ⇒ Object
Returns the String in snake_case.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/savon/core_ext/string.rb', line 9 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 |
#strip_namespace ⇒ Object
Returns the String without namespace.
30 31 32 |
# File 'lib/savon/core_ext/string.rb', line 30 def strip_namespace gsub /(.+:)(.+)/, '\2' end |
#to_soap_value ⇒ Object
Returns the String as a SOAP request compliant value.
43 44 45 |
# File 'lib/savon/core_ext/string.rb', line 43 def to_soap_value to_s end |