Public Suffix List for mruby. The purpose of this project is mruby port of publicsuffix-ruby.
mruby-publicsuffix aims at porting from publicsuffix-ruby, but there's some differences, so it cannot provide totally the same functionality.
- mruby >= 1.3.0
You can add conf.gem line to build_config.rb
:
MRuby::Build.new do |conf|
# ... (snip) ...
conf.gem mgem: 'mruby-publicsuffix'
end
PublicSuffix.domain
extracts the domain out from a given name and returns it as String class.
PublicSuffix.domain('google.com')
# => "google.com"
If given a domain with subdomains, returning the domain.
PublicSuffix.domain('www.google.com')
# => "google.com"
PublicSuffix.domain('www.google.co.uk')
# => "google.co.uk"
This library automatically recognizes FQDN (Fully Qualified Domain Names). A FQDN is a domain name that end with a trailing dot.
PublicSuffix.domain("www.google.com.")
# => "google.com"
PublicSuffix.parse
parses a domain and returns an object of PublicSuffix::Domain
class. This method support a domain with subdomains.
domain = PublicSuffix.parse('www.google.com')
# => #<PublicSuffix::Domain:0x7fa3bf84c9b0>
Checks whether a given domain is assigned and allowed, without actually parsing it. This method doesn't care whether domain is a domain or subdomain. The validation is performed using the default PublicSuffix::List
.
Simple validation example:
PublicSuffix.valid?("google.com")
# => true
# Explicitly forbidden, it is listed as a private domain
> PublicSuffix.valid?("blogspot.com")
# => false
# Unknown/not-listed TLD domains are valid by default
> PublicSuffix.valid?("example.tldnotlisted")
# => true
Strict validation (without applying the default * rule):
> PublicSuffix.valid?("example.tldnotlisted", PublicSuffix::List.default, nil)
# => false
under the MIT License:
- see LICENSE file