Class: Rbkb::Http::FormUrlencodedParams

Inherits:
Parameters
  • Object
show all
Defined in:
lib/rbkb/http/parameters.rb

Overview

The FormUrlencodedParams class is for Parameters values in the form of ‘q=foo&l=1&z=baz’ as found in GET query strings and application/www-form-urlencoded or application/x-url-encoded POST contents.

Instance Method Summary collapse

Methods inherited from Parameters

#delete_param, #get_all, #get_all_values_for, #get_param, #get_value_for, #initialize, parse, #set_all_for, #set_param

Methods included from CommonInterface

#_common_init, #opts, #opts=

Constructor Details

This class inherits a constructor from Rbkb::Http::Parameters

Instance Method Details

#capture(str, url_dec = false) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rbkb/http/parameters.rb', line 111

def capture(str, url_dec=false)
  raise "arg 0 must be a string" unless str.is_a? String
  str.split('&').each do |p| 
    k,v = p.split('=',2)
    if url_dec
      k = k.urldec
      v = v.urldec
    end
    self << [k, v]
  end
  return self
end

#to_raw(url_enc = false) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rbkb/http/parameters.rb', line 97

def to_raw(url_enc=false)
  self.map do |k,v|
    if url_enc
      k = k.urlenc
      v = v.urlenc
    end
    if v
      "#{k}=#{v}" 
    else 
      "#{k}"
    end
  end.join('&')
end