merge(oth)
public
Args
Description
Merges two URI’s.
Usage
require 'uri'
uri = URI.parse("http://my.example.com")
p uri.merge("/main.rbx?page=1")
Show source
def merge(oth)
rel = parser.send(:convert_to_uri, oth)
if rel.absolute?
return rel
end
unless self.absolute?
raise BadURIError, "both URI are relative"
end
base = self.dup
authority = rel.userinfo || rel.host || rel.port
if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
base.fragment=(rel.fragment) if rel.fragment
return base
end
base.query = nil
base.fragment=(nil)
if !authority
base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path
else
base.set_path(rel.path) if rel.path
end
base.set_userinfo(rel.userinfo) if rel.userinfo
base.set_host(rel.host) if rel.host
base.set_port(rel.port) if rel.port
base.query = rel.query if rel.query
base.fragment=(rel.fragment) if rel.fragment
return base
end