Sha256: a36620c03ee6dfd350333f3bf20fac73acb2da9b1e4e8bcb1b9804d41316fbe6
Contents?: true
Size: 842 Bytes
Versions: 3
Compression:
Stored size: 842 Bytes
Contents
module Buff class Encode class << self def encode(arg) raise_error_for_incorrect_input(arg) arg = arg[:schedules] if arg.respond_to?(:keys) arg.map.with_index do |item, index| process_schedule(item, index) end.join("&") end private def raise_error_for_incorrect_input(arg) unless arg.kind_of?(Hash) || arg.kind_of?(Array) raise ArgumentError, "Input must be/inherit from Hash or Array" end end def process_schedule(item, index) pairs_for(item).map do |key, value| "schedules[#{index}][#{key}][]=#{value}" end.join("&") end def pairs_for(item) uri = Addressable::URI.new uri.query_values = item uri.query.split("&").map {|p| p.split("=")} end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
buff-0.0.6 | lib/buff/encode.rb |
buff-0.0.5 | lib/buff/encode.rb |
buff-0.0.4 | lib/buff/encode.rb |