module PublicSuffix

Defined in:

public_suffix.cr
public_suffix/domain.cr
public_suffix/errors.cr
public_suffix/list.cr
public_suffix/rule.cr
public_suffix/version.cr

Constant Summary

BANG = '!'
DOT = '.'
STAR = '*'
VERSION = "0.1.0"

Class Method Summary

Class Method Detail

def self.domain(name, **options) #

Attempt to parse the name and returns the domain, if valid.

This method doesn't raise. Instead, it returns nil if the domain is not valid for whatever reason.

@param [String, #to_s] name The domain name or fully qualified domain name to parse. @param [PublicSuffix::List] list The rule list to search, defaults to the default {PublicSuffix::List} @param [Boolean] ignore_private @return [String]


[View source]
def self.generated_list #

this list autogenerated, not edit it, generated at 2019-01-18 02:05:03 +03:00


[View source]
def self.normalize(name) #

Pretend we know how to deal with user input.


[View source]
def self.parse(name : String, list = List.default, default_rule = list.default_rule, ignore_private = false) #

Parses +name+ and returns the {PublicSuffix::Domain} instance.

@example Parse a valid domain PublicSuffix.parse("google.com")

=> #<PublicSuffix::Domain:0x007fec2e51e588 @sld="google", @tld="com", @trd=nil>

@example Parse a valid subdomain PublicSuffix.parse("www.google.com")

=> #<PublicSuffix::Domain:0x007fec276d4cf8 @sld="google", @tld="com", @trd="www">

@example Parse a fully qualified domain PublicSuffix.parse("google.com.")

=> #<PublicSuffix::Domain:0x007fec257caf38 @sld="google", @tld="com", @trd=nil>

@example Parse a fully qualified domain (subdomain) PublicSuffix.parse("www.google.com.")

=> #<PublicSuffix::Domain:0x007fec27b6bca8 @sld="google", @tld="com", @trd="www">

@example Parse an invalid (unlisted) domain PublicSuffix.parse("x.yz")

=> #<PublicSuffix::Domain:0x007fec2f49bec0 @sld="x", @tld="yz", @trd=nil>

@example Parse an invalid (unlisted) domain with strict checking (without applying the default * rule) PublicSuffix.parse("x.yz", default_rule: nil)

=> PublicSuffix::DomainInvalid: x.yz is not a valid domain

@example Parse an URL (not supported, only domains) PublicSuffix.parse("http://www.google.com")

=> PublicSuffix::DomainInvalid: http://www.google.com is not expected to contain a scheme

@param [String, #to_s] name The domain name or fully qualified domain name to parse. @param [PublicSuffix::List] list The rule list to search, defaults to the default {PublicSuffix::List} @param [Boolean] ignore_private @return [PublicSuffix::Domain]

@raise [PublicSuffix::DomainInvalid] If domain is not a valid domain. @raise [PublicSuffix::DomainNotAllowed] If a rule for +domain+ is found, but the rule doesn't allow +domain+.


[View source]
def self.valid?(name : String, list = List.default, default_rule = list.default_rule, ignore_private = false) #

Checks whether +domain+ is assigned and allowed, without actually parsing it.

This method doesn't care whether domain is a domain or subdomain. The validation is performed using the default {PublicSuffix::List}.

@example Validate a valid domain PublicSuffix.valid?("example.com")

=> true

@example Validate a valid subdomain PublicSuffix.valid?("www.example.com")

=> true

@example Validate a not-listed domain PublicSuffix.valid?("example.tldnotlisted")

=> true

@example Validate a not-listed domain with strict checking (without applying the default * rule) PublicSuffix.valid?("example.tldnotlisted")

=> true

PublicSuffix.valid?("example.tldnotlisted", default_rule: nil)

=> false

@example Validate a fully qualified domain PublicSuffix.valid?("google.com.")

=> true

PublicSuffix.valid?("www.google.com.")

=> true

@example Check an URL (which is not a valid domain) PublicSuffix.valid?("http://www.example.com")

=> false

@param [String, #to_s] name The domain name or fully qualified domain name to validate. @param [Boolean] ignore_private @return [Boolean]


[View source]