Module: Savon::CoreExt::String

Defined in:
lib/savon/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#lower_camelcaseObject

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

#map_soap_responseObject

Translates SOAP response values to Ruby Objects.



40
41
42
43
44
45
# File 'lib/savon/core_ext/string.rb', line 40

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

#snakecaseObject

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.

Returns:

  • (Boolean)


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

#strip_namespaceObject

Returns the String without namespace.



35
36
37
# File 'lib/savon/core_ext/string.rb', line 35

def strip_namespace
  split(":").last
end