class PublicSuffix::Rule::Wildcard

Wildcard represents a wildcard rule (e.g. *.co.uk).

Public Class Methods

new(definition, private: false) click to toggle source

Initializes a new rule from definition.

The wildcard “*” is removed from the value, as it's common for each wildcard rule.

@param definition [String] the rule as defined in the PSL

Calls superclass method PublicSuffix::Rule::Base.new
# File lib/public_suffix/rule.rb, line 222
def initialize(definition, private: false)
  super(definition.to_s[2..-1], private: private)
end

Public Instance Methods

decompose(domain) click to toggle source

Decomposes the domain name according to rule properties.

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

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

Gets the length of this rule for comparison, represented by the number of dot-separated parts in the rule plus 1 for the *.

@return [Integer] The length of the rule.

# File lib/public_suffix/rule.rb, line 256
def length
  @length ||= parts.length + 1 # * counts as 1
end
parts() click to toggle source

dot-split rule value and returns all rule parts in the order they appear in the value.

@return [Array<String>]

# File lib/public_suffix/rule.rb, line 247
def parts
  @value.split(DOT)
end
rule() click to toggle source

Gets the original rule definition.

@return [String] The rule definition.

# File lib/public_suffix/rule.rb, line 229
def rule
  value == "" ? STAR : STAR + DOT + value
end