Class: PublicSuffix::Rule::Wildcard

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

Overview

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

Instance Attribute Summary

Attributes inherited from Base

#private, #value

Instance Method Summary collapse

Methods inherited from Base

#==, #match?

Constructor Details

#initialize(definition, **options) ⇒ Wildcard

Initializes a new rule from definition.

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

Parameters:

  • definition (String)

    the rule as defined in the PSL



229
230
231
# File 'lib/public_suffix/rule.rb', line 229

def initialize(definition, **options)
  super(definition.to_s[2..-1], **options)
end

Instance Method Details

#decompose(domain) ⇒ Array<String>

Decomposes the domain name according to rule properties.

Parameters:

  • name (String, #to_s)

    The domain name to decompose

Returns:

  • (Array<String>)

    The array with [trd + sld, tld].



244
245
246
247
248
# File 'lib/public_suffix/rule.rb', line 244

def decompose(domain)
  suffix = ([".*?"] + parts).join('\.')
  matches = domain.to_s.match(/^(.*)\.(#{suffix})$/)
  matches ? matches[1..2] : [nil, nil]
end

#lengthInteger

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

Returns:

  • (Integer)

    The length of the rule.



263
264
265
# File 'lib/public_suffix/rule.rb', line 263

def length
  @length ||= parts.length + 1 # * counts as 1
end

#partsArray<String>

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

Returns:

  • (Array<String>)


254
255
256
# File 'lib/public_suffix/rule.rb', line 254

def parts
  @value.split(DOT)
end

#ruleString

Gets the original rule definition.

Returns:

  • (String)

    The rule definition.



236
237
238
# File 'lib/public_suffix/rule.rb', line 236

def rule
  value == "" ? STAR : STAR + DOT + value
end