Adam Wenham
2014-06-05 15:03:24 UTC
Hi guys,
I'm having some problems on good old Codewars, writing a method that can
take a URL and return just the domain.
I've managed to create a Regex in Rubular (http://rubular.com/r/C7wAZRq8OA)
that passes my tests, but I'm having trouble implementing it properly.
Here are my tests:
Test.assert_equals(domain_name("http://github.com/carbonfive/raygun"),
"github")
Test.assert_equals(domain_name("http://www.zombie-bites.com"),
"zombie-bites")
Test.assert_equals(domain_name("https://www.cnet.com"), "cnet")
Here's my method:
def domain_name(url)
url.match(/https*:\/\/w*\.*(\w*\-*\w*)./)
end
As far as I can tell, this should work. Any ideas on what I'm doing wrong?
Thanks!
I'm having some problems on good old Codewars, writing a method that can
take a URL and return just the domain.
I've managed to create a Regex in Rubular (http://rubular.com/r/C7wAZRq8OA)
that passes my tests, but I'm having trouble implementing it properly.
Here are my tests:
Test.assert_equals(domain_name("http://github.com/carbonfive/raygun"),
"github")
Test.assert_equals(domain_name("http://www.zombie-bites.com"),
"zombie-bites")
Test.assert_equals(domain_name("https://www.cnet.com"), "cnet")
Here's my method:
def domain_name(url)
url.match(/https*:\/\/w*\.*(\w*\-*\w*)./)
end
As far as I can tell, this should work. Any ideas on what I'm doing wrong?
Thanks!
--
== People often come up to me and ask "What the heck are you doing in my
shed!?" ==
== People often come up to me and ask "What the heck are you doing in my
shed!?" ==