Class: Circus::Agents::Encoding

Inherits:
Object
  • Object
show all
Defined in:
lib/circus/agents/encoding.rb

Class Method Summary collapse

Class Method Details

.decode(str) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/circus/agents/encoding.rb', line 18

def self.decode(str)
  parsed = CGI::parse(str)
  result = {}
  parsed.each do |k, v|
    if v.length == 1
      result[k] = v.first
    else
      result[k] = v
    end
  end
  result
end

.encode(params, sep = '&') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/circus/agents/encoding.rb', line 6

def self.encode(params, sep = '&')
  params.map do |k,v|
    if v.is_a? Array
      v.map do |iv|
        "#{CGI.escape(k.to_s)}=#{CGI.escape(iv.to_s)}"
      end.join(sep)
    else
      "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
    end
  end.join(sep)
end