module Ethon::Easies::Util

def build_query_pairs(hash)

Returns:
  • (Array) - The array of query pairs.

Parameters:
  • hash (Hash) -- The hash to go through.

Other tags:
    Example: Build query pairs. -
def build_query_pairs(hash)
  pairs = []
  recursive = Proc.new do |h, prefix|
    h.each_pair do |k,v|
      key = prefix == '' ? k : "#{prefix}[#{k}]"
      case v
      when Hash
        recursive.call(v, key)
      when Array
        v.each { |x| pairs << [key, x]  }
      when File, Tempfile
        pairs << [Util.escape_zero_byte(key), file_info(v)]
      else
        pairs << [Util.escape_zero_byte(key), Util.escape_zero_byte(v)]
      end
    end
  end
  recursive.call(hash, '')
  pairs
end