Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Domain Name parser based on the Public Suffix List.

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.rdoc

Domain Name Parser

DomainName is a Ruby domain name parser based on the Public Suffix List available at publicsuffix.org/.

What is the Public Suffix List?

The Public Suffix List is a cross-vendor initiative to provide an accurate list of domain name suffixes.

The Public Suffix List is an initiative of the Mozilla Project, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.

A “public suffix” is one under which Internet users can directly register names. Some examples of public suffixes are “.com”, “.co.uk” and “pvt.k12.wy.us”. The Public Suffix List is a list of all known public suffixes.

Source publicsuffix.org/.

Why the Public Suffix List is better than any available Regular Expression parser?

Since there was and remains no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list. This is the aim of the Public Suffix List.

Not convinced yet? Check out a real world example: stackoverflow.com/questions/288810/get-the-subdomain-from-a-url

Requirements

  • Ruby >= 1.8.6 (not tested with previous versions)

Successfully tested against

  • Ruby 1.8.6 / 1.8.7 / 1.9.1

  • MacRuby 0.4

  • Ruby Enterprise Edition

Installation

Via RubyGems/Gemcutter

$ gem install domain_name --source http://gemcutter.org

You might need administrator privileges on your system to install it.

Usage

Example domain without subdomains.

domain = DomainName.parse("google.com")
domain.tld
# => "com"
domain.domain
# => "google"
domain.subdomain
# => nil

Example domain with subdomains.

domain = DomainName.parse("www.google.com")
domain.tld
# => "com"
domain.domain
# => "google"
domain.subdomain
# => "www"

Credits

Author

Simone Carletti <weppos@weppos.net>

Changelog

See the CHANGELOG.rdoc file for details.

License

Copyright © 2009 Simone Carletti, DomainName is released under the MIT license.

Something went wrong with that request. Please try again.