Class | PublicSuffixService::Domain |
In: |
lib/public_suffix_service/domain.rb
|
Parent: | Object |
Splits a string into its possible labels as a domain in reverse order from the input string.
The input is not validated, but it is assumed to be a valid domain.
The domain name to split.
@return [Array<String>]
@example
domain_to_labels('google.com') # => ['com', 'google'] domain_to_labels('google.co.uk') # => ['uk', 'co', 'google']
Creates and returns a new {PublicSuffixService::Domain} instance.
@overload initialize(tld)
Initializes with a +tld+. @param [String] tld The TLD (extension)
@overload initialize(tld, sld)
Initializes with a +tld+ and +sld+. @param [String] tld The TLD (extension) @param [String] sld The TRD (domain)
@overload initialize(tld, sld, trd)
Initializes with a +tld+, +sld+ and +trd+. @param [String] tld The TLD (extension) @param [String] sld The SLD (domain) @param [String] tld The TRD (subdomain)
@yield [self] Yields on self. @yieldparam [PublicSuffixService::Domain] self The newly creates instance
@example Initialize with a TLD
PublicSuffixService::Domain.new("com") # => #<PublicSuffixService::Domain @tld="com">
@example Initialize with a TLD and SLD
PublicSuffixService::Domain.new("com", "example") # => #<PublicSuffixService::Domain @tld="com", @trd=nil>
@example Initialize with a TLD, SLD and TRD
PublicSuffixService::Domain.new("com", "example", "wwww") # => #<PublicSuffixService::Domain @tld="com", @trd=nil, @sld="example">
Returns a domain-like representation of this object if the object is a {domain?}, nil otherwise.
PublicSuffixService::Domain.new("com").domain # => nil PublicSuffixService::Domain.new("com", "google").domain # => "google.com" PublicSuffixService::Domain.new("com", "google", "www").domain # => "www.google.com"
This method doesn‘t validate the input. It handles the domain as a valid domain name and simply applies the necessary transformations.
# This is an invalid domain PublicSuffixService::Domain.new("zip", "google").domain # => "google.zip"
This method returns a FQD, not just the domain part. To get the domain part, use sld (aka second level domain).
PublicSuffixService::Domain.new("com", "google", "www").domain # => "google.com" PublicSuffixService::Domain.new("com", "google", "www").sld # => "google"
@return [String]
Checks whether self looks like a domain.
This method doesn‘t actually validate the domain. It only checks whether the instance contains a value for the {tld} and {sld} attributes. If you also want to validate the domain, use {valid_domain?} instead.
@return [Boolean]
@example
PublicSuffixService::Domain.new("com").domain? # => false PublicSuffixService::Domain.new("com", "google").domain? # => true PublicSuffixService::Domain.new("com", "google", "www").domain? # => true # This is an invalid domain, but returns true # because this method doesn't validate the content. PublicSuffixService::Domain.new("zip", "google").domain? # => true
@see subdomain?
Returns the rule matching this domain in the default {PublicSuffixService::RuleList}.
@return [PublicSuffixService::Rule::Base, nil]
The rule instance a rule matches current domain, nil if no rule is found.
Returns a domain-like representation of this object if the object is a {subdomain?}, nil otherwise.
PublicSuffixService::Domain.new("com").subdomain # => nil PublicSuffixService::Domain.new("com", "google").subdomain # => nil PublicSuffixService::Domain.new("com", "google", "www").subdomain # => "www.google.com"
This method doesn‘t validate the input. It handles the domain as a valid domain name and simply applies the necessary transformations.
# This is an invalid domain PublicSuffixService::Domain.new("zip", "google", "www").subdomain # => "www.google.zip"
This method returns a FQD, not just the domain part. To get the domain part, use tld (aka third level domain).
PublicSuffixService::Domain.new("com", "google", "www").subdomain # => "www.google.com" PublicSuffixService::Domain.new("com", "google", "www").trd # => "www"
@return [String]
Checks whether self looks like a subdomain.
This method doesn‘t actually validate the subdomain. It only checks whether the instance contains a value for the {tld}, {sld} and {trd} attributes. If you also want to validate the domain, use {valid_subdomain?} instead.
@return [Boolean]
@example
PublicSuffixService::Domain.new("com").subdomain? # => false PublicSuffixService::Domain.new("com", "google").subdomain? # => false PublicSuffixService::Domain.new("com", "google", "www").subdomain? # => true # This is an invalid domain, but returns true # because this method doesn't validate the content. PublicSuffixService::Domain.new("zip", "google", "www").subdomain? # => true
@see domain?
Returns an array containing the domain parts.
@return [Array<String, nil>]
@example
PublicSuffixService::Domain.new("google.com").to_a # => [nil, "google", "com"] PublicSuffixService::Domain.new("www.google.com").to_a # => [nil, "google", "com"]
Checks whether self is assigned and allowed according to default {RuleList}.
This method triggers a new rule lookup in the default {RuleList}, which is a quite intensive task.
@return [Boolean]
@example Check a valid domain
Domain.new("com", "example").valid? # => true
@example Check a valid subdomain
Domain.new("com", "example", "www").valid? # => true
@example Check a not-assigned domain
Domain.new("zip", "example").valid? # => false
@example Check a not-allowed domain
Domain.new("do", "example").valid? # => false Domain.new("do", "example", "www").valid? # => true
Checks whether self looks like a domain and validates according to default {RuleList}.
@return [Boolean]
@example
PublicSuffixService::Domain.new("com").domain? # => false PublicSuffixService::Domain.new("com", "google").domain? # => true PublicSuffixService::Domain.new("com", "google", "www").domain? # => true # This is an invalid domain PublicSuffixService::Domain.new("zip", "google").false? # => true
@see domain? @see valid?
Checks whether self looks like a subdomain and validates according to default {RuleList}.
@return [Boolean]
@example
PublicSuffixService::Domain.new("com").subdomain? # => false PublicSuffixService::Domain.new("com", "google").subdomain? # => false PublicSuffixService::Domain.new("com", "google", "www").subdomain? # => true # This is an invalid domain PublicSuffixService::Domain.new("zip", "google", "www").subdomain? # => false
@see subdomain? @see valid?