class PublicSuffix::Rule::Exception

Exception represents an exception rule (e.g. !parliament.uk).

Public Class Methods

Initializes a new rule from the content.

@param content [#to_s] the content of the rule @param private [Boolean]

# File lib/public_suffix/rule.rb, line 271
def self.build(content, private: false)
  new(value: content.to_s[1..], private: private)
end

Public Instance Methods

Decomposes the domain name according to rule properties.

@param domain [#to_s] The domain name to decompose @return [Array<String>] The array with [trd + sld, tld].

# File lib/public_suffix/rule.rb, line 286
def decompose(domain)
  suffix = parts.join('\.')
  matches = domain.to_s.match(/^(.*)\.(#{suffix})$/)
  matches ? matches[1..2] : [nil, nil]
end

dot-split rule value and returns all rule parts in the order they appear in the value. The leftmost label is not considered a label.

See publicsuffix.org/format/: If the prevailing rule is a exception rule, modify it by removing the leftmost label.

@return [Array<String>]

# File lib/public_suffix/rule.rb, line 301
def parts
  @value.split(DOT)[1..]
end

Gets the original rule definition.

@return [String] The rule definition.

# File lib/public_suffix/rule.rb, line 278
def rule
  BANG + value
end