module Rack::Typhoeus::Middleware::ParamsDecoder::Helper
def convert(hash)
-
(Arraya/Hash)
-
Parameters:
-
hash
(Hash
) -- The Hash to convert into an Array.
def convert(hash) if encoded?(hash) hash.sort{ |a, b| a[0].to_i <=> b[0].to_i }.map{ |key, value| value } else hash end end
def decode(hash)
def decode(hash) decode!(hash.dup) end
def decode!(hash)
-
(Hash)
- Hash with properly decoded nested arrays.
Parameters:
-
hash
(Hash
) -- . This Hash will be modified!
def decode!(hash) return hash unless hash.is_a?(Hash) hash.each_pair do |key,value| if value.is_a?(Hash) decode!(value) hash[key] = convert(value) end end hash end
def decode_typhoeus_arrays
- Author: - Dwayne Macgowan
Other tags:
- Example: Use directly in a Rails controller. -
def decode_typhoeus_arrays decode!(params) end
def encoded?(hash)
-
(Boolean)
- True if its a encoded Array, else false.
Parameters:
-
hash
(Hash
) --
def encoded?(hash) return false if hash.empty? if hash.keys.size > 1 keys = hash.keys.map{|i| i.to_i if i.respond_to?(:to_i)}.sort keys == hash.keys.size.times.to_a else hash.keys.first =~ /0/ end end