Module: PublicSuffix::Rule

Defined in:
lib/public_suffix/rule.rb

Overview

A Rule is a special object which holds a single definition of the Public Suffix List.

There are 3 types of rules, each one represented by a specific subclass within the PublicSuffix::Rule namespace.

To create a new Rule, use the #factory method.

PublicSuffix::Rule.factory("ar")
# => #<PublicSuffix::Rule::Normal>

Defined Under Namespace

Classes: Base, Entry, Exception, Normal, Wildcard

Class Method Summary collapse

Class Method Details

.defaultPublicSuffix::Rule::Wildcard

The default rule to use if no rule match.

The default rule is “*”. From publicsuffix.org/list/:

> If no rules match, the prevailing rule is “*”.

Returns:



344
345
346
# File 'lib/public_suffix/rule.rb', line 344

def self.default
  factory(STAR)
end

.factory(content, private: false) ⇒ PublicSuffix::Rule::*

Takes the name of the rule, detects the specific rule class and creates a new instance of that class. The name becomes the rule value.

Examples:

Creates a Normal rule

PublicSuffix::Rule.factory("ar")
# => #<PublicSuffix::Rule::Normal>

Creates a Wildcard rule

PublicSuffix::Rule.factory("*.ar")
# => #<PublicSuffix::Rule::Wildcard>

Creates an Exception rule

PublicSuffix::Rule.factory("!congresodelalengua3.ar")
# => #<PublicSuffix::Rule::Exception>

Parameters:

  • content (#to_s)

    the content of the rule

Returns:



326
327
328
329
330
331
332
333
334
335
# File 'lib/public_suffix/rule.rb', line 326

def self.factory(content, private: false)
  case content.to_s[0, 1]
  when STAR
    Wildcard
  when BANG
    Exception
  else
    Normal
  end.build(content, private: private)
end