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
Class Method Summary collapse
-
.build(content, private: false) ⇒ Object
Initializes a new rule from the content.
Instance Method Summary collapse
-
#decompose(domain) ⇒ Array<String>
Decomposes the domain name according to rule properties.
-
#initialize(value:, length: nil, private: false) ⇒ Wildcard
constructor
Initializes a new rule.
-
#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(value:, length: nil, private: false) ⇒ Wildcard
Initializes a new rule.
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.
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.
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 |
#parts ⇒ Array<String>
dot-split rule value and returns all rule parts in the order they appear in the value.
258 259 260 |
# File 'lib/public_suffix/rule.rb', line 258 def parts @value.split(DOT) end |