Class: String
Class Method Summary collapse
-
.random(length = 100) ⇒ Object
Returns a random String of a given
length
.
Instance Method Summary collapse
-
#ends_with?(suffix) ⇒ Boolean
Returns whether the String ends with a given
suffix
. -
#lower_camelcase ⇒ Object
Returns the String in lowerCamelCase.
-
#map_soap_response ⇒ Object
Translates SOAP response values to Ruby Objects.
-
#snakecase ⇒ Object
Returns the String in snake_case.
-
#starts_with?(prefix) ⇒ Boolean
Returns whether the String starts with a given
prefix
. -
#strip_namespace ⇒ Object
Returns the String without namespace.
-
#to_soap_key ⇒ Object
Returns the Object as a SOAP request compliant key.
-
#to_soap_value ⇒ Object
Returns the String as a SOAP value.
-
#to_soap_value! ⇒ Object
Convert the String into a SOAP value without escaping special characters.
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
#ends_with?(suffix) ⇒ Boolean
Returns whether the String ends with a given suffix
.
36 37 38 39 |
# File 'lib/savon/core_ext/string.rb', line 36 def ends_with?(suffix) suffix = suffix.to_s self[-suffix.length, suffix.length] == suffix end |
#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 Ruby Objects.
47 48 49 50 51 52 |
# File 'lib/savon/core_ext/string.rb', line 47 def map_soap_response return DateTime.parse(self) if Savon::SOAP::DateTimeRegexp === 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 |
#starts_with?(prefix) ⇒ Boolean
Returns whether the String starts with a given prefix
.
30 31 32 33 |
# File 'lib/savon/core_ext/string.rb', line 30 def starts_with?(prefix) prefix = prefix.to_s self[0, prefix.length] == prefix end |
#strip_namespace ⇒ Object
Returns the String without namespace.
42 43 44 |
# File 'lib/savon/core_ext/string.rb', line 42 def strip_namespace split(":").last end |
#to_soap_key ⇒ Object
Returns the Object as a SOAP request compliant key.
55 56 57 |
# File 'lib/savon/core_ext/string.rb', line 55 def to_soap_key self[-1, 1] == "!" ? chop : self end |
#to_soap_value ⇒ Object
Returns the String as a SOAP value. Escapes special characters for XML.
60 61 62 |
# File 'lib/savon/core_ext/string.rb', line 60 def to_soap_value self #CGI.escapeHTML self end |
#to_soap_value! ⇒ Object
Convert the String into a SOAP value without escaping special characters.
65 66 67 |
# File 'lib/savon/core_ext/string.rb', line 65 def to_soap_value! self end |