Skip to content

Commit c38b2d0

Browse files
author
Matt Kelly
committed
Add helper for Array of pairs param
1 parent 5a79261 commit c38b2d0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

lib/http/form_data/multipart/param.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ def self.coerce(data)
5959
params
6060
end
6161

62+
# Flattens given Array of `data` Array pairs into an array of `Param`'s.
63+
# Nested array are unwinded.
64+
# Behavior is similar to `URL.encode_www_form`.
65+
#
66+
# @param [Array] data
67+
# @return [Array<FormData::MultiPart::Param>]
68+
def self.coerce_array_of_pairs(data)
69+
params = []
70+
71+
data.each_cons(2) do |name, values|
72+
Array(values).each do |value|
73+
params << new(name, value)
74+
end
75+
end
76+
77+
params
78+
end
79+
6280
private
6381

6482
def header

0 commit comments

Comments
 (0)