Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lazy_domain

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy_domain

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

LazyDomain

Build Status Code Climate Gem Version

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")
# => #<PublicSuffix::Domain>
domain.tld
# => "com"
domain.sld
# => "google"
domain.trd
# => nil
domain.domain
# => "google.com"
domain.subdomain
# => nil

Example domain with subdomains.

domain = LazyDomain.parse("www.google.com")
# => #<PublicSuffix::Domain>
domain.tld
# => "com"
domain.sld
# => "google"
domain.trd
# => "www"
domain.domain
# => "google.com"
domain.subdomain
# => "www.google.com"

Simple validation example.

LazyDomain.valid?("google.com")
# => true

LazyDomain.valid?("www.google.com")
# => true

LazyDomain.valid?("x.yz")
# => false

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.


# => #<PublicSuffix::Domain:0x0055c2344f0168 @sld="google", @tld="com", @trd="abc.defg.hijk">

Enjoy!

FAQs

Package last updated on 12 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc