Sha256: 1b1bffe759df619e4bb48e693e4520cbb89a16e213f705e45a577e3d732c333a

Contents?: true

Size: 1.01 KB

Versions: 754

Compression:

Stored size: 1.01 KB

Contents

require 'cgi'

module Seahorse
  # @api private
  module Util
    class << self

      def irregular_inflections(hash)
        @irregular_inflections.update(hash)
        @irregular_regex = Regexp.new(@irregular_inflections.keys.join('|'))
      end

      # @param [String] string
      # @return [String] Returns the underscored version of the given string.
      def underscore(string)
        new_string = string.dup
        new_string.gsub!(@irregular_regex) { |word| "_#{@irregular_inflections[word]}" }
        new_string.gsub!(/([A-Z0-9]+)([A-Z][a-z])/, '\1_\2'.freeze)
        new_string = new_string.scan(/[a-z0-9]+|\d+|[A-Z0-9]+[a-z]*/).join('_'.freeze)
        new_string.downcase!
        new_string
      end

      def uri_escape(string)
        CGI.escape(string.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
      end

      def uri_path_escape(path)
        path.gsub(/[^\/]+/) { |part| uri_escape(part) }
      end

    end

    @irregular_inflections = {}

    irregular_inflections('ETag' => 'etag')

  end
end

Version data entries

754 entries across 754 versions & 1 rubygems

Version Path
aws-sdk-core-2.11.632 lib/seahorse/util.rb
aws-sdk-core-2.11.631 lib/seahorse/util.rb
aws-sdk-core-2.11.630 lib/seahorse/util.rb
aws-sdk-core-2.11.629 lib/seahorse/util.rb
aws-sdk-core-2.11.628 lib/seahorse/util.rb
aws-sdk-core-2.11.627 lib/seahorse/util.rb
aws-sdk-core-2.11.626 lib/seahorse/util.rb
aws-sdk-core-2.11.625 lib/seahorse/util.rb
aws-sdk-core-2.11.624 lib/seahorse/util.rb
aws-sdk-core-2.11.623 lib/seahorse/util.rb
aws-sdk-core-2.11.622 lib/seahorse/util.rb
aws-sdk-core-2.11.621 lib/seahorse/util.rb
aws-sdk-core-2.11.620 lib/seahorse/util.rb
aws-sdk-core-2.11.619 lib/seahorse/util.rb
aws-sdk-core-2.11.618 lib/seahorse/util.rb
aws-sdk-core-2.11.617 lib/seahorse/util.rb
aws-sdk-core-2.11.616 lib/seahorse/util.rb
aws-sdk-core-2.11.615 lib/seahorse/util.rb
aws-sdk-core-2.11.614 lib/seahorse/util.rb
aws-sdk-core-2.11.613 lib/seahorse/util.rb