Class: PublicSuffix::Rule::Wildcard
- Defined in:
- lib/public_suffix/rule.rb
Overview
Wildcard represents a wildcard rule (e.g. *.co.uk).
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#decompose(domain) ⇒ Array<String>
Decomposes the domain name according to rule properties.
-
#initialize(definition, **options) ⇒ Wildcard
constructor
Initializes a new rule from
definition
. -
#length ⇒ Integer
Gets the length of this rule for comparison, represented by the number of dot-separated parts in the rule plus 1 for the *.
-
#parts ⇒ Array<String>
dot-split rule value and returns all rule parts in the order they appear in the value.
-
#rule ⇒ String
Gets the original rule definition.
Methods inherited from Base
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.
229 230 231 |
# File 'lib/public_suffix/rule.rb', line 229 def initialize(definition, **) super(definition.to_s[2..-1], **) end |
Instance Method Details
#decompose(domain) ⇒ Array<String>
Decomposes the domain name according to rule properties.
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 |
#length ⇒ Integer
Gets the length of this rule for comparison, represented by the number of dot-separated parts in the rule plus 1 for the *.
263 264 265 |
# File 'lib/public_suffix/rule.rb', line 263 def length @length ||= parts.length + 1 # * counts as 1 end |
#parts ⇒ Array<String>
dot-split rule value and returns all rule parts in the order they appear in the value.
254 255 256 |
# File 'lib/public_suffix/rule.rb', line 254 def parts @value.split(DOT) end |