class PublicSuffix

Overview

The Public Suffix List library.

The Public Suffix List is "a cross-vendor initiative to provide an accurate list of domain name suffixes". Such a list is necessary because "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...".

public_suffix is a small Crystal library designed to make the Public Suffix List easier to use. The library will transparently download the latest list of rules, parse the rules, and optionally cache them. Source URL, cache directory, and cache expiry are all configurable.

Defined in:

public_suffix.cr
public_suffix/cached_list.cr
public_suffix/parser.cr

Constant Summary

VERSION = "0.1.1"

Constructors

Instance Method Summary

Constructor Detail

def self.new(**kwargs) #

Creates a new PublicSuffix instance. By default, it fetches and caches the official list of rules. Specify the cache directory with cache_dir (the default is the system temp directory) and the cache expiry with cache_expiry_period in seconds (the default it 30 days). An expiry of 0 means cache indefinitely; a negative value means do not cache. Download rules from another source by specifying the url.

PublicSuffix.new(cache_dir: "/tmp", cache_expiry_period: 3600, url: "file:///var/data/test.dat")

[View source]

Instance Method Detail

def cdn(domain) #

Returns the full canonical domain name:

cdn("www.city.kawasaki.jp") # => "city.kawasaki.jp"

[View source]
def split(domain) #

Splits the domain name into a three-element list consisting of (from right to left) the top-level domain name, the canonical name, and everything else:

split("www.city.kawasaki.jp") # => ["www", "city", "kawasaki.jp"]

[View source]
def take(domain, n = 1) #

Takes the specified number off the list. Returns an empty list if the specified number aren't available.


[View source]
def tld(domain) #

Returns the top-level domain name:

tld("www.city.kawasaki.jp") # => "kawasaki.jp"

[View source]