Sha256: 919889e0613afa63e36feeda45392cc355a9fb243b6c2c8dcd6bbafb72501f6d

Contents?: true

Size: 703 Bytes

Versions: 13

Compression:

Stored size: 703 Bytes

Contents

require 'cgi'

module VaultedBilling
  module CoreExt
    module Hash
      def to_querystring
        to_a.reject { |pair| pair.last.nil? }.
          sort_by { |item| item.first.to_s }.
          collect { |key, value| "#{key}=#{value}" }.join('&')
      end

      module ClassMethods
        def from_querystring(string)
          return {} if string.nil?
          ::Hash[*(string.split(/&/).
            collect { |i| i.split(/=/) }.
            collect { |e| e.size == 1 ? (e << '') : e }.flatten.
            collect { |e| CGI.unescape(e) })]
        end
      end
    end
  end
end

::Hash.send :include, VaultedBilling::CoreExt::Hash
::Hash.extend(VaultedBilling::CoreExt::Hash::ClassMethods)

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
vaulted_billing-1.4.0 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.3.1 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.3.0 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.2.1 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.2.0 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.1.6 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.1.5 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.1.4 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.1.3 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.1.2 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.1.0 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.0.2 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-1.0.1 lib/vaulted_billing/core_ext/hash.rb