1
说我有这样的URL:http://www.rubinassociatespa.com/AccountantBocaRaton.html
如何在Ruby中使用URI类从域中提取根域?
我只想提取基本域 - http://www.rubinassociatespa.com
我无法弄清楚如何使用Ruby URI类,但是没有做的字符串操作来做到这一点。
[36] pry(#<YPCrawler::PageParser>)> @url
=> "http://www.rubinassociatespa.com/AccountantBocaRaton.html"
[37] pry(#<YPCrawler::PageParser>)> URI(@url).scheme
=> "http"
[38] pry(#<YPCrawler::PageParser>)> URI(@url).host
=> "www.rubinassociatespa.com"
要使用字符串操作做到这一点,我将不得不做这样的事情:
URI(@url).scheme + "://" + URI(@url).host
但似乎哈克。
是否有更“原生”的方式来做到这一点?一些很酷的方法或类似URI
类可以优雅地处理这个?
有没有开箱即用的方法。 – Ilya