LazyDomain
Parse varying urls with PublicSuffix the easy way.
Description
The PublicSuffix gem works great if you give it nice, clean urls WITHOUT a transfer protocol. But what if your application has one (or multiple) urls with or without protocols?
LazyDomain assumes it could be either way and uses URI to make up the difference. Because URI can only parse a url WITH a protocol, Lazy Domain automatically adds 'http://' if it is not already present in a url. Now, you can easily use PublicSuffix for varying urls.
Installation
$ gem install lazy_domain
Usage
Because LazyDomain is simply a wrapper for PublicSuffix, the usage is exactly the same.
Basic Usage
Example domain without subdomains.
domain = LazyDomain.parse("google.com")
domain.tld
domain.sld
domain.trd
domain.domain
domain.subdomain
Example domain with subdomains.
domain = LazyDomain.parse("www.google.com")
domain.tld
domain.sld
domain.trd
domain.domain
domain.subdomain
Simple validation example.
LazyDomain.valid?("google.com")
LazyDomain.valid?("www.google.com")
LazyDomain.valid?("x.yz")
Advanced Usage
You can do everything mentioned above, but the magic of LazyDomain is you can now pass different types of urls!
For example, all of this...
domain = LazyDomain.parse("google.com")
domain = LazyDomain.parse("http://google.com")
domain = LazyDomain.parse("ftp://google.com")
domain = LazyDomain.parse("somethingcrazy://google.com")
domain = LazyDomain.parse("http://abc.defg.hijk.google.com")
domain = LazyDomain.parse("http://abc.defg.hijk.google.com/asubdirectory/andanother")
...returns something like this.
Enjoy!