Sha256: dac1a35d817842667640c2c40541ad181c685f7a6538ea27c8756a12e6852edb

Contents?: true

Size: 723 Bytes

Versions: 1

Compression:

Stored size: 723 Bytes

Contents

module GLPI
  module SDK
    module HashConverter
      def self.to_query(params)
        URI.encode_www_form(encode(params))
      end

      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

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

      private_class_method :append_key, :encode
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glpi-sdk-ruby-0.0.2 lib/glpi/sdk/util/hash_converter.rb