Sha256: c55ffa49caf829e92572a72a0ddfa7a78ac4d7b2458747d9fcdc6499a16e66a6

Contents?: true

Size: 643 Bytes

Versions: 12

Compression:

Stored size: 643 Bytes

Contents

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)]
        end
      end
    end
  end
end

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vaulted_billing-1.0.0 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.15 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.14 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.13 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.12 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.11 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.10 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.9 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.8 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.7 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.6 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.5 lib/vaulted_billing/core_ext/hash.rb