class URL::ParamsHash
Public Class Methods
from_string(str)
click to toggle source
# File lib/url/helper_classes.rb, line 69 def from_string str params = URL::ParamsHash.new str.split('&').each do |myp| key,value = myp.split('=') value = CGI.unescape(value) if value params[key.to_sym] = value if key end params end
Public Instance Methods
reverse_merge!(other)
click to toggle source
# File lib/url/helper_classes.rb, line 27 def reverse_merge! other replace self|other end
to_s(questionmark=true)
click to toggle source
Merges the array into a parameter string of the form ?key=value&foo=bar
# File lib/url/helper_classes.rb, line 32 def to_s(questionmark=true) return '' if empty? str = questionmark ? '?' : '' str << to_a.inject(Array.new) do |ret,param| key = param[0].to_s val = param[1] if param && val if val.is_a?(Hash) # TODO: Make this recusrive val.each do |param_key,param_val| param_key = CGI.escape("#{key}[#{param_key}]") param_val = CGI.escape(param_val.to_s) ret << %Q{#{param_key}=#{param_val}} end elsif val.is_a?(Array) # TODO: Make this recusrive val.each_with_index do |param_val,i| param_key = CGI.escape("#{key}[]") param_val = CGI.escape(param_val.to_s) ret << %Q{#{param_key}=#{param_val}} end else val = val.to_s val = CGI.escape(val)# if val =~ /(\/|\?|\s)/ ret << %{#{param[0].to_s}=#{val}} end elsif param ret << param[0].to_s end ret end.join('&') str end
|(other)
click to toggle source
# File lib/url/helper_classes.rb, line 19 def | other unless other.is_a? ParamsHash other = other.to_hash if other.respond_to?(:to_hash) other = ParamsHash[other] end other.merge(self) end