Class | PublicSuffix::List |
In: |
lib/public_suffix/list.rb
|
Parent: | Object |
A {PublicSuffix::List} is a collection of one or more {PublicSuffix::Rule}.
Given a {PublicSuffix::List}, you can add or remove {PublicSuffix::Rule}, iterate all items in the list or search for the first rule which matches a specific domain name.
# Create a new list list = PublicSuffix::List.new # Push two rules to the list list << PublicSuffix::Rule.factory("it") list << PublicSuffix::Rule.factory("com") # Get the size of the list list.size # => 2 # Search for the rule matching given domain list.find("example.com") # => #<PublicSuffix::Rule::Normal> list.find("example.org") # => nil
You can create as many {PublicSuffix::List} you want. The {PublicSuffix::List.default} rule list is used to tokenize and validate a domain.
{PublicSuffix::List} implements Enumerable module.
indexes | [R] |
Gets the naive index, a hash that with the keys being the first label of
every rule pointing to an array of integers (indexes of the rules in
@rules).
@return [Array] |
rules | [R] |
Gets the array of rules.
@return [Array<PublicSuffix::Rule::*>] |
Gets the default rule list. Initializes a new {PublicSuffix::List} parsing the content of {PublicSuffix::List.default_definition}, if required.
@return [PublicSuffix::List]
Sets the default rule list to value.
@param [PublicSuffix::List] value
The new rule list.
@return [PublicSuffix::List]
Gets the default definition list. Can be any IOStream including a File or a simple String. The object must respond to each_line.
@return [File]
Initializes an empty {PublicSuffix::List}.
@yield [self] Yields on self. @yieldparam [PublicSuffix::List] self The newly created instance.
Parse given input treating the content as Public Suffix List.
See publicsuffix.org/format/ for more details about input format.
@param [String] input The rule list to parse.
@return [Array<PublicSuffix::Rule::*>]
Resets the default rule list and reinitialize it parsing the content of {PublicSuffix::List.default_definition}.
@return [PublicSuffix::List]
Checks whether two lists are equal.
List one is equal to two, if two is an instance of {PublicSuffix::List} and each +PublicSuffix::Rule::*+ in list one is available in list two, in the same order.
@param [PublicSuffix::List] other
The List to compare.
@return [Boolean]
Adds the given object to the list
and optionally refreshes the rule index.
@param [PublicSuffix::Rule::*] rule The rule to add to the list. @param [Boolean] index Set to true to recreate the rule index after the rule has been added to the list. @return [self] @see #create_index!
Creates a naive index for +@rules+. Just a hash that will tell us where the elements of +@rules+ are relative to its first {PublicSuffix::Rule::Base#labels} element.
For instance if @rules[5] and @rules[4] are the only elements of the list where Rule#labels.first is ‘us’ @indexes[‘us’] #=> [5,4], that way in select we can avoid mapping every single rule against the candidate domain.
Returns the most appropriate rule for domain.
From the Public Suffix List documentation:
@param [String, to_s] domain The domain name.
@return [PublicSuffix::Rule::*, nil]
Selects all the rules matching given domain.
Will use +@indexes+ to try only the rules that share the same first label, that will speed up things when using +List.find(‘foo’)+ a lot.
@param [String, to_s] domain The domain name.
@return [Array<PublicSuffix::Rule::*>]