Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Created March 18, 2015 13:20
Show Gist options
  • Select an option

  • Save ripienaar/110b68855d64a841e1aa to your computer and use it in GitHub Desktop.

Select an option

Save ripienaar/110b68855d64a841e1aa to your computer and use it in GitHub Desktop.
def parse(url)
res = url.split("//")
temp = res[1]
output = temp.split(":")
username = output[0]
text = output[1]
pos = text.rindex('@')
length = text.length()
password = text[0,pos]
@host = text[pos+1, length]
@user = URI.decode(username)
@password = URI.decode(password)
end
@ripienaar
Copy link
Author

def parse(url)
  @url = URI.parse(url)
  @query = Hash.new([])
  @query = CGI.parse(@url.query) if @url.query

  @user = @url.user
  @password = URI.decode(@url.password)
  @host = @url.host
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment