Sha256: 2af4e26e5ecb5fb9bc196aa8e5b8b5bfabce3be0ea39e1e4fe15f19a5358cac0

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

require "savon/soap"

module Savon
  module CoreExt
    module String

      # 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 whether the String starts with a given +prefix+.
      def starts_with?(prefix)
        prefix = prefix.to_s
        self[0, prefix.length] == prefix
      end unless defined? starts_with?

      # Returns the String without namespace.
      def strip_namespace
        split(":").last
      end

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

    end
  end
end

String.send :include, Savon::CoreExt::String

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
search_biomodel-1.0.0 search_biomodel/ruby/1.8/gems/savon-0.9.2/lib/savon/core_ext/string.rb
savon-0.9.2 lib/savon/core_ext/string.rb
s-savon-0.8.6 lib/savon/core_ext/string.rb
savon-0.9.1 lib/savon/core_ext/string.rb
savon-0.9.0 lib/savon/core_ext/string.rb
savon-0.8.6 lib/savon/core_ext/string.rb
savon-0.8.5 lib/savon/core_ext/string.rb
savon-0.8.4 lib/savon/core_ext/string.rb
savon-0.8.3 lib/savon/core_ext/string.rb