Sha256: 17ec824741b8b471cef1fd2e82c16fe8b28c2d4b663eecd2dca3c78e78957ff9

Contents?: true

Size: 1.1 KB

Versions: 20

Compression:

Stored size: 1.1 KB

Contents

class String

  # Returns a random String of a given +length+.
  def self.random(length = 100)
    (0...length).map { ("a".."z").to_a[rand(26)] }.join
  end

  # Returns the String in snake_case.
  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

  # Returns the String in lowerCamelCase.
  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

  # Returns the String without namespace.
  def strip_namespace
    gsub /(.+:)(.+)/, '\2'
  end

  # Translates SOAP response values to more convenient Ruby Objects.
  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

  # Returns the String as a SOAP request compliant value.
  def to_soap_value
    to_s
  end

end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
savon-xaop-0.7.2.7 lib/savon/core_ext/string.rb
savon-xaop-0.7.2.6 lib/savon/core_ext/string.rb
savon-xaop-0.7.2.5 lib/savon/core_ext/string.rb
johnreitano-savon-0.7.2.1 lib/savon/core_ext/string.rb
savon-xaop-0.7.2.4 lib/savon/core_ext/string.rb
savon-xaop-0.7.2.3 lib/savon/core_ext/string.rb
savon-xaop-0.7.2.2 lib/savon/core_ext/string.rb
savon-xaop-0.7.2.1 lib/savon/core_ext/string.rb
savon-0.7.4 lib/savon/core_ext/string.rb
savon-0.7.3 lib/savon/core_ext/string.rb
savon-0.7.2 lib/savon/core_ext/string.rb
savon-0.7.1 lib/savon/core_ext/string.rb
savon-0.7.0 lib/savon/core_ext/string.rb
julianmorrison-savon-0.6.8 lib/savon/core_ext/string.rb
savon-0.6.8 lib/savon/core_ext/string.rb
savon-0.6.7 lib/savon/core_ext/string.rb
savon-0.6.6 lib/savon/core_ext/string.rb
savon-0.6.5 lib/savon/core_ext/string.rb
savon-0.6.4 lib/savon/core_ext/string.rb
savon-0.6.3 lib/savon/core_ext/string.rb