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

#length, #private, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #match?

Constructor Details

#initialize(value:, length: nil, private: false) ⇒ Wildcard

Initializes a new rule.

Parameters:

  • value (String)
  • length (Integer) (defaults to: nil)
  • private (Boolean) (defaults to: false)


232
233
234
235
# File 'lib/public_suffix/rule.rb', line 232

def initialize(value:, length: nil, private: false)
  super
  length or @length += 1 # * counts as 1
end

Class Method Details

.build(content, private: false) ⇒ Object

Initializes a new rule from the content.

Parameters:

  • content (String)

    the content of the rule

  • private (Boolean) (defaults to: false)


223
224
225
# File 'lib/public_suffix/rule.rb', line 223

def self.build(content, private: false)
  new(value: content.to_s[2..], 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].



248
249
250
251
252
# File 'lib/public_suffix/rule.rb', line 248

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.

Returns:

  • (Array<String>)


258
259
260
# File 'lib/public_suffix/rule.rb', line 258

def parts
  @value.split(DOT)
end

#ruleString

Gets the original rule definition.

Returns:

  • (String)

    The rule definition.



240
241
242
# File 'lib/public_suffix/rule.rb', line 240

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