Sha256: bee87a07b12a23ccad529df698ee0fa79965fb1d2c3f6eaeaeca9677b2287b5f

Contents?: true

Size: 652 Bytes

Versions: 181

Compression:

Stored size: 652 Bytes

Contents

# Thanks https://mensfeld.pl/2012/01/converting-nested-hash-into-http-url-params-hash-version-in-ruby/
module Jets::Mega
  module HashConverter
    def self.encode(value, key = nil, out_hash = {})
      case value
      when Hash  then
        value.each { |k,v| encode(v, append_key(key,k), out_hash) }
        out_hash
      when Array then
        value.each { |v| encode(v, "#{key}[]", out_hash) }
        out_hash
      when nil   then ''
      else
        out_hash[key] = value
        out_hash
      end
    end

    private

    def self.append_key(root_key, key)
      root_key.nil? ? :"#{key}" : :"#{root_key}[#{key.to_s}]"
    end
  end
end

Version data entries

181 entries across 181 versions & 4 rubygems

Version Path
jets-4.0.2 lib/jets/mega/hash_converter.rb
jets-4.0.1 lib/jets/mega/hash_converter.rb
jets-4.0.0 lib/jets/mega/hash_converter.rb
jets-3.2.2 lib/jets/mega/hash_converter.rb
jets-3.2.1 lib/jets/mega/hash_converter.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/mega/hash_converter.rb
jets-3.2.0 lib/jets/mega/hash_converter.rb
jets-3.1.5 lib/jets/mega/hash_converter.rb
jets-3.1.4 lib/jets/mega/hash_converter.rb
jets-3.1.3 lib/jets/mega/hash_converter.rb
jets-3.1.2 lib/jets/mega/hash_converter.rb
jets-3.1.1 lib/jets/mega/hash_converter.rb
jets-3.1.0 lib/jets/mega/hash_converter.rb
jets-3.0.23 lib/jets/mega/hash_converter.rb
jets-3.0.22 lib/jets/mega/hash_converter.rb
jets-3.0.21 lib/jets/mega/hash_converter.rb
jets-3.0.20 lib/jets/mega/hash_converter.rb
jets-3.0.19 lib/jets/mega/hash_converter.rb
jets-3.0.18 lib/jets/mega/hash_converter.rb
jets-3.0.17 lib/jets/mega/hash_converter.rb