Class: PublicSuffix::Rule::Wildcard

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

Instance Attribute Summary

Attributes inherited from Base

#labels, #name, #value

Instance Method Summary collapse

Methods inherited from Base

#==, #allow?, #match?, #type, type

Constructor Details

#initialize(name) ⇒ Wildcard

Initializes a new rule with name.

Parameters:

  • name (String)

    The name of this rule.



281
282
283
# File 'lib/public_suffix/rule.rb', line 281

def initialize(name)
  super(name, name.to_s[2..-1])
end

Instance Method Details

#decompose(domain) ⇒ Array<String>

Decomposes the domain according to rule properties.

Parameters:

  • domain (String, #to_s)

    The domain name to decompose.

Returns:

  • (Array<String>)

    The array with [trd + sld, tld].



309
310
311
312
# File 'lib/public_suffix/rule.rb', line 309

def decompose(domain)
  domain.to_s.chomp(".") =~ /^(.*)\.(.*?\.#{parts.join('\.')})$/
  [$1, $2]
end

#lengthInteger

Overwrites the default implementation to cope with the * char.

Returns:

  • (Integer)

    The number of parts.



297
298
299
# File 'lib/public_suffix/rule.rb', line 297

def 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>)


289
290
291
# File 'lib/public_suffix/rule.rb', line 289

def parts
  @parts ||= @value.split(".")
end