struct

PublicSuffix::Rule::Base

Inherits Struct < Value < Object

@api internal = Abstract rule class

This represent the base class for a Rule definition in the {Public Suffix List}[https://publicsuffix.org].

This is intended to be an Abstract class and you shouldn't create a direct instance. The only purpose of this class is to expose a common interface for all the available subclasses.

  • {PublicSuffix::Rule::Normal}
  • {PublicSuffix::Rule::Exception}
  • {PublicSuffix::Rule::Wildcard}

Properties

A rule is composed by 4 properties:

value - A normalized version of the rule name. The normalization process depends on rule tpe.

Here's an example

PublicSuffix::Rule.factory("*.google.com") #<PublicSuffix::Rule::Wildcard:0x1015c14b0 @value="google.com"

Rule Creation

The best way to create a new rule is passing the rule name to the <tt>PublicSuffix::Rule.factory</tt> method.

PublicSuffix::Rule.factory("com")

=> PublicSuffix::Rule::Normal

PublicSuffix::Rule.factory("*.com")

=> PublicSuffix::Rule::Wildcard

This method will detect the rule type and create an instance from the proper rule class.

Rule Usage

A rule describes the composition of a domain name and explains how to tokenize the name into tld, sld and trd.

To use a rule, you first need to be sure the name you want to tokenize can be handled by the current rule. You can use the <tt>#match?</tt> method.

rule = PublicSuffix::Rule.factory("com")

rule.match?("google.com")

=> true

rule.match?("google.com")

=> false

Rule order is significant. A name can match more than one rule. See the {Public Suffix Documentation}[http://publicsuffix.org/format/] to learn more about rule priority.

When you have the right rule, you can use it to tokenize the domain name.

rule = PublicSuffix::Rule.factory("com")

rule.decompose("google.com")

=> ["google", "com"]

rule.decompose("www.google.com")

=> ["www.google", "com"]

@abstract

Constructors

new(value : String, length : Int32 | Nil = nil, _private : Bool = false)

Initializes a new rule.

@param value [String] @param private [Boolean]

Source

Class methods

build(content, _private = false)

Initializes a new rule from the content.

@param content [String] the content of the rule @param private [Boolean]

Source

Instance methods

_private

@return [Boolean] true if the rule is a private domain

Source
decompose(domain : String) : Tuple(String | Nil, String | Nil)
Source
length

@return [Int32] the length of the rule

Source
match?(name)

Checks if this rule matches +name+.

A domain name is said to match a rule if and only if all of the following conditions are met:

  • When the domain and rule are split into corresponding labels, that the domain contains as many or more labels than the rule.
  • Beginning with the right-most labels of both the domain and the rule, and continuing for all labels in the rule, one finds that for every pair, either they are identical, or that the label from the rule is "*".

@see https://publicsuffix.org/list/

@example PublicSuffix::Rule.factory("com").match?("example.com")

=> true

PublicSuffix::Rule.factory("com").match?("example.net")

=> false

@param name [String] the domain name to check @return [Boolean]

Source
parts
Source
value

@return [String] the rule definition

Source