class

PublicSuffix

Inherits Reference < Object

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.

Constants

VERSION = "0.1.1"

Constructors

new

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")

Source

Instance methods

cdn(domain)

Returns the full canonical domain name: cdn("www.city.kawasaki.jp") # => "city.kawasaki.jp"

Source
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"]

Source
take(domain, n = 1)

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

Source
tld(domain)

Returns the top-level domain name: tld("www.city.kawasaki.jp") # => "kawasaki.jp"

Source

Nested types