Module: HTTParty::HashConversions
- Defined in:
- lib/pearson_kitchen_manager.rb
Class Method Summary collapse
-
.normalize_param(key, value) ⇒ String
This key value pair as a param.
Class Method Details
.normalize_param(key, value) ⇒ String
Returns This key value pair as a param.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/pearson_kitchen_manager.rb', line 80 def self.normalize_param(key, value) param = '' stack = [] if value.is_a?(Array) param << Hash[*(0...value.length).to_a.zip(value).flatten].map {|i,element| normalize_param("#{key}[#{i}]", element)}.join elsif value.is_a?(Hash) stack << [key,value] else param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&" end stack.each do |parent, hash| hash.each do |key, value| if value.is_a?(Hash) stack << ["#{parent}[#{key}]", value] else param << normalize_param("#{parent}[#{key}]", value) end end end param end |