class PublicSuffix::List
- PublicSuffix::List
- Reference
- Object
Overview
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.
Defined in:
public_suffix/list.crConstant Summary
-
DEFAULT_LIST_PATH =
File.expand_path("../../publicsuffix-ruby/data/list.txt", "/srv/crystaldoc.info/github-kostya-public_suffix-master/src/public_suffix")
Constructors
-
.new
Initializes an empty {PublicSuffix::List}.
Class Method Summary
-
.default
Gets the default rule list.
-
.default=(value : Nil | PublicSuffix::List)
Sets the default rule list to +value+.
-
.parse(input, private_domains = true)
Parse given +input+ treating the content as Public Suffix List.
Instance Method Summary
- #add(rule : String, _private = false)
-
#add(rule : Rule::Base)
Adds the given object to the list and optionally refreshes the rule index.
-
#clear
Removes all rules.
-
#default_rule
Gets the default rule.
-
#empty?
Checks whether the list is empty.
-
#filter(name : String, ignore_private = false)
Selects all the rules matching given hostame.
-
#find(name, default = default_rule, **options)
Finds and returns the rule corresponding to the longest public suffix for the hostname.
- #rules : Hash(String, PublicSuffix::Rule::Base)
-
#size
Gets the number of rules in the list.
Constructor Detail
Initializes an empty {PublicSuffix::List}.
@yield [self] Yields on self. @yieldparam [PublicSuffix::List] self The newly created instance.
Class Method Detail
Gets the default rule list.
Initializes a new {PublicSuffix::List} parsing the content of {PublicSuffix::List.default_list_content}, if required.
@return [PublicSuffix::List]
Sets the default rule list to +value+.
@param [PublicSuffix::List] value The new rule list.
@return [PublicSuffix::List]
Parse given +input+ treating the content as Public Suffix List.
See http://publicsuffix.org/format/ for more details about input format.
@param string [#each_line] The list to parse. @param private_domains [Boolean] whether to ignore the private domains section. @return [ArrayPublicSuffix::Rule::*]
Instance Method Detail
Adds the given object to the list and optionally refreshes the rule index.
@param rule [PublicSuffix::Rule::*] the rule to add to the list @return [self]
Gets the default rule.
@see PublicSuffix::Rule.default_rule
@return [PublicSuffix::Rule::*]
Selects all the rules matching given hostame.
If ignore_private
is set to true, the algorithm will skip the rules that are flagged as
private domain. Note that the rules will still be part of the loop.
If you frequently need to access lists ignoring the private domains,
you should create a list that doesn't include these domains setting the
private_domains: false
option when calling {.parse}.
Note that this method is currently private, as you should not rely on it. Instead, the public interface is {#find}. The current internal algorithm allows to return all matching rules, but different data structures may not be able to do it, and instead would return only the match. For this reason, you should rely on {#find}.
@param name [#to_s] the hostname @param ignore_private [Boolean] @return [ArrayPublicSuffix::Rule::*]
Finds and returns the rule corresponding to the longest public suffix for the hostname.
@param name [#to_s] the hostname @param default [PublicSuffix::Rule::] the default rule to return in case no rule matches @return [PublicSuffix::Rule::]