Class: PublicSuffix::Rule::Exception

Inherits:
Base
  • Object
show all
Defined in:
lib/public_suffix/rule.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Base

#length, #private, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #initialize, #match?

Constructor Details

This class inherits a constructor from PublicSuffix::Rule::Base

Class Method Details

.build(content, private: false) ⇒ Object

Initializes a new rule from the content.

Parameters:

  • content (#to_s)

    the content of the rule

  • private (Boolean) (defaults to: false)


271
272
273
# File 'lib/public_suffix/rule.rb', line 271

def self.build(content, private: false)
  new(value: content.to_s[1..], private: private)
end

Instance Method Details

#decompose(domain) ⇒ Array<String>

Decomposes the domain name according to rule properties.

Parameters:

  • domain (#to_s)

    The domain name to decompose

Returns:

  • (Array<String>)

    The array with [trd + sld, tld].



286
287
288
289
290
# 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

#partsArray<String>

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.

Returns:

  • (Array<String>)


301
302
303
# File 'lib/public_suffix/rule.rb', line 301

def parts
  @value.split(DOT)[1..]
end

#ruleString

Gets the original rule definition.

Returns:

  • (String)

    The rule definition.



278
279
280
# File 'lib/public_suffix/rule.rb', line 278

def rule
  BANG + value
end